Basically the structure of a C program consists of four modules.
- Preprocessor Directives (Includes, Macros)
- Global declarations (Functions, Variables..)
- The main function (Program execution starts here..)
- User-defined functions (Option to the user)
First C Program
main() // First function invoked by the compiler
printf("WELCOME TO C PROGRAMMING");//To display the things in double quotes
WELCOME TO C PROGRAMMING
- 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