Menu

Structure of a C Program

Basically the structure of a C program consists of four modules.

  1. Preprocessor Directives (Includes, Macros)
  2. Global declarations (Functions, Variables..)
  3. The main function (Program execution starts here..)
  4. User-defined functions (Option to the user)

First C Program

      #include<stdio.h>
      main() // First function invoked by the compiler
      {
         printf("WELCOME TO C PROGRAMMING");//To display the things in double quotes
      }

Output

            WELCOME TO C PROGRAMMING

Program description

  • The first line of the program, which tells a compiler to include header files for library functions.
  • In the main function, the program execution will begin.
  • The print(...) is a function available in C is to print "Welcome to c programming" on the screen.
  • The comment symbol /*....*/ will be ignored by the compiler.
  • Comments can be inserted anywhere in the C program.
  • Nested comments are ignored by the compiler.
  • Braces are generally used for grouping of statements.
  • Generally, all letters are written in lowercase letters.
  • Every C statement ends with a semicolon.

Compile and execute c program

  • Open text editor
  • Open the file name pg1.c and paste the above program into it and save the file(ESC button+w+q)
  • for compile type cc pg1.c
  • for output type ./a.out