Hello World Program in C

Here we will write our first C program. A Hello World program.


#include <stdio.h>

int main() 
    printf("Hello World!");
    return 0;

Know it:

  • #include <stdio.h> is a pre-processor directive. When the above program is compiled the compiler replaces the first line with entire contents of stdio.h file. The stdio.h (Standard Input/Output) is called as header file and contains functions for basic input/output operations.
  • int main() is a function and defines the starting point of our program. It contains two parts:
    int It is the return type of the function. It specifies that the main() function should return an integer value when its work is finished.
    main() It is an identifier or name of the function.
    Note: The starting point of any program in C is defined by main function.
  • The next line contains pair of curly braces. In C we use a pair of curly braces to define a block of statements. An opening curly brace is always followed by a closing curly brace.
  • printf(); is a function used to print any data on screen. Anything inside the double quotes " " will be printed as it is on screen.
  • return 0; returns an integer value to the operating system or the Runtime environment of C acknowledging OS/C Runtime Environment that the program has terminated successfully.

If you have written the above program same as in the source code without making any mistake then it should print Hello World! on the screen.
View next C tutorial Declaring variables in C.

Any doubt or suggestion write here. I will try my best to help. Before posting your code you must escape it to view. To format your source code and use format highlighting, post your source code inside
< pre>< code >----Your Source Code---- < / code > < / pre > (Remove spaces from pre and code tags)

No comments:

Post a Comment