Skip to main content

Hello World Example In C Programming | VCMIT

Hello World Example



A C program basically consists of the following parts −


  • Preprocessor Commands
  • Functions
  • Variables
  • Statements & Expressions
  • Comments


Let us look at a simple code that would print the words "Hello World" −

INPUT

#include <stdio.h>
void main {
   /* my first program in C */
   printf("Hello, World! \n");
   getch;
}

Let us take a look at the various parts of the above program −


  • The first line of the program #include <stdio.h> is a preprocessor command, which tells a C compiler to include stdio.h file before going to actual compilation.
  • The next line int main() is the main function where the program execution begins.
  • The next line /*...*/ will be ignored by the compiler and it has been put to add additional comments in the program. So such lines are called comments in the program.
  • The next line printf(...) is another function available in C which causes the message "Hello, World!" to be displayed on the screen.
  • The next line return 0; terminates the main() function and returns the value 0.


Compile and Execute C Program

Let us see how to save the source code in a file, and how to compile and run it. Following are the simple steps −


  • Open a text editor and add the above-mentioned code.
  • Save the file as hello.c
  • Open a command prompt and go to the directory where you have saved the file.
  • Type gcc hello.c and press enter to compile your code.
  • If there are no errors in your code, the command prompt will take you to the next line and would generate a.out executable file.
  • Now, type a.out to execute your program.
  • You will see the output "Hello World" printed on the screen.


OUTPUT

Hello, World

Comments

Popular posts from this blog

Create House Like Structure Perform Operations Program In C | VCMIT

Program to create a house like figure and perform the following operations.  Scaling about the origin followed by translation.  Scaling with reference to an arbitrary point. Reflect about the line y = mx + c. INPUT #include <stdio.h> #include <graphics.h> #include <stdlib.h> #include <math.h> #include <conio.h> void reset (int h[][2]) { int val[9][2] = { { 50, 50 },{ 75, 50 },{ 75, 75 },{ 100, 75 }, { 100, 50 },{ 125, 50 },{ 125, 100 },{ 87, 125 },{ 50, 100 } }; int i; for (i=0; i<9; i++) { h[i][0] = val[i][0]-50; h[i][1] = val[i][1]-50; } } void draw (int h[][2]) { int i; setlinestyle (DOTTED_LINE, 0, 1); line (320, 0, 320, 480); line (0, 240, 640, 240); setlinestyle (SOLID_LINE, 0, 1); for (i=0; i<8; i++) line (320+h[i][0], 240-h[i][1], 320+h[i+1][0], 240-h[i+1][1]); line (320+h[0][0], 240-h[0][1], 320+h[8][0], 240-h[8][1]); } void rotate (int h[][2], float angle) { int i; for (i=0; i<9; i++) { int xnew, ynew; xnew = h[i][0] * cos (angle) - h[i]

Software Engineering - Waterfall Model | VCMIT

Waterfall model Winston Royce introduced the Waterfall Model in 1970.This model has five phases: Requirements analysis and specification, design, implementation, and unit testing, integration and system testing, and operation and maintenance. The steps always follow in this order and do not overlap. The developer must complete every phase before the next phase begins. This model is named "Waterfall Model", because its diagrammatic representation resembles a cascade of waterfalls. 1. Requirements analysis and specification phase: The aim of this phase is to understand the exact requirements of the customer and to document them properly. Both the customer and the software developer work together so as to document all the functions, performance, and interfacing requirement of the software. It describes the "what" of the system to be produced and not "how."In this phase, a large document called Software Requirement Specification (SRS) document is created whic

What Is Software? | VCMIT

Software Software is a set of instructions, data or programs used to operate computers and execute specific tasks. Opposite of hardware, which describes the physical aspects of a computer, software is a generic term used to refer to applications, scripts and programs that run on a device. Software can be thought of as the variable part of a computer, and hardware the invariable part. Software is often divided into categories. Application software refers to user-downloaded programs that fulfill a want or need. Examples of applications include office suites, database programs, web browsers, word processors, software development tools, image editors and communication platforms. System software includes operating systems and any program that supports application software.