1. Introduction to C Language.
2. Features of C language:
3. Disadvantages of C language
4. C program structure:
1. #include<stdio.h>
2.
3. int main()
4. {
5.
6. printf("Hello World \n");
7.
8. return 0;
9. }
The first line “#include” is called as pre-processor directive. “stdio.h” is called as header file. This header file has declarations about standard input and output functions.
Next line is “int main()”. main() is the starting point of any c program. There is a return type specifies “int”, that informs compiler that the function returns a value is of type int.
Next is opening brace, indicating starting of function main().
Next line is a “printf()” function. This is used to display the output to standard console. Note that every statements inside a function has ended with semicolon. This informs the compiler that the statement has ended. And this semi-colon is mandatory to terminate a statement.
Next is “return 0;”. This will return the program execution back to the called function. In this case compiler. In C, returning value 0 indicates program completed without any issues.
Last line is closing brace, indicating end of function main().
To compile a C program in Linux use the following command:
gcc hello.c –o hello.o
To run the executed program, use below command:
./hello.o
5. C Comments:
Comments provide effective ways of knowing the functionality of a function. It is always a good practice to include comments in beginning of a function with a short description of what it does.
The part written inside comments will be ignored by the compiler and the comments will be stripped off while compiling the program.
C supports 2 types of comments:
1. Single line comment:
// This is a single line comment
2. Multiline comment:
/* This is
an example of
multiline comment
*/
Example:
#include<stdio.h>
int main()
{
int num = 1; // integer variable
/* Multi line comment
num = num + 1;
Above code will not be executed,
as it is in comment
*/
return 0;
}