C Programs are written in a Compilar program. There are many C compilars available now a days, but mostly used compilar is Turbo C. Though C and C++ programs, both are written on the same compilar still we call it C Compilar.
Following is a sample C program just to get an idea about how does a C program look. We have an explanation of all the statements written here in this sample program. Have a look:
In C language, header files are special files with [.h] extension. These files store the definitions of different complex keywords, functions and other grammar elements. When we need to call any predefined function in our program, we must include the respective header file.
Though there are many header files but here we discuss following mazor five only:
stdio.h | conio.h | math.h | stdlib.h | string.h |
---|---|---|---|---|
printf() | clrscr() | pow() | abs() | strlen() |
scanf() | getch() | sqrt() | exit() | strcmp() |
getchar() | log() | delay() | strcpy() | |
putchar() | sin() | malloc() | strcat() | |
gets() | calloc() | |||
puts() | realloc() |
main() is a function in C language that constitutes the entire program logic in a bundle and when we execute it, the compiler throws its output to the console.
clrscr() is a predefined function in C language that clears the console screen.
Variables are memory locations that are used to store temporary data. For an operation, the operands can be stored in variables.
Here, three variables named a, b and c are declared to be used as integers.
Variable initialization refers to assigning or storing constant values onto the memory locations reserved by them.
Here, variables a and b are assigned integer values 4 and 6 respectively.
Arithmetic expressions are used to perform mathematical operations as and when required.
Here, values in variables a and b are multiplied and their product is assigned to the variable c.
printf() is a predefined function in C language that is used to print something onto the console.
Here,
In the first statement, printf() is printing the text string given as arguments withing the parenthesis.
In the second statement, value of variable c is printed by using controle string %d for decimal integers.
getch() is a predefined function in C language that is used to read or get a character from the console.
Here we've called it not to get a character but to hold the console screen (waiting for that character).