Basic Structure of C Program

Getting Started

Basic Structure of C Program

First step is to understand the structure of a “ C “ programming language using simple C program.
Let us look a simple code that would print the word “Learn C :) ”.

#include <stdio.h>
int main()
{
 /* My First program in C :) */
 printf("Learn C :)");
 return 0;
 }
 

Output

Learn C :)

S.no Coding Explanation
1 #include <stdio.h> This is a preprocessor command it tells the C compiler to include “stdio.h” from the C library before compiling a C program.
2 int main() This is the main function from where execution of any C program begins.
3 { This indicates the beginning of the main function.
4 /*_some_comments_*/
or
// some_comments
The comments are ignored by compiler. [ “ /*..*/ ”,” //... “ ]
5 printf("Learn C :)"); printf command prints the output onto the screen.
6 return 0; This command terminates C program (main function) and returns 0 value to the main function.
7 } This indicates the end of the main function.
 

Semicolon ( ; )

In C program, the semicolon is a statement terminator. In each individual statement must be ended with a semicolon.

Comma operator ( , )

The coma operator is used to separates the elements of variables in data type or element in array etc.
Ex: int a=7,b,c;

Whitespace (   )

Whitespace is the term used in C to describe blanks space like tabs, horizontal tab, newline characters(pressing Enter key and write coding in new line ) and space between comments. Whitespace separates one part of a statement from another and enables the compiler to identify elements in a statement.
Ex: int i, void main(), etc..,.

The following two example program will help you to learn more about whitespace.
Example: 1:-More Whitespace

#include <stdio.h>
  int main()
  {
  printf
  (
 " Learn C :) "
 )
  ;
  return 0;
  } 

Remember at least one whitespace character (space) between int main(), int i;, return 0;, etc..,
Example: 2:-

#include <stdio.h>
int main(){printf(" Learn C :) ");return 0;} 
The above two program output will be same

Output

Learn C :)