"HARD WORK BEATS TALENT WHEN TALENT DOSEN'T WORK HARD."
"HARD WORK BEATS TALENT WHEN TALENT DOSEN'T WORK HARD."
In this section you will learn Structure of C program. How is C program look like? There are total 5 section of C program. You will learn basic skeleton of C program or you can say basic things of C program.
C program contain group of statement. All statement execute in program but some of the statement not execute. That are called comment statement. Comment are the C program statement which will not execute. We can also say it None-Executable statement.
Why we make comment in program that question come in beginner programmer mind. Basically comment are used to provide the some useful information or some small documentation about the program. Most of the time we use comment statement in large program.
In C language we have two types comments.
To make the single line comment we use two backward slash " // " symbol. This is called single line comment statement. In this program we are giving the information about the program by comment section. Comment section never will execute.
Now see the program code. By comment we are giving the information about the program logic. Like we are printing the value of variable " a ".
void main() { int a=10; clrscr(); //printing the value of variable a. printf("Value of A is: %d",a); getch(); }
Value of A is: 10
To make the multiline comment we use two backward slash with two asterisk symbol “ /* */ “. This is called multiline comment statement. In this program we are giving the information about the program by comment section. Comment section never will execute.
Now in this program code we are making multiline comment by giving more information.
void main() { int a=10; clrscr(); /*printing the value of a variable by taking single variable. this is our simple program of C.*/ printf("Value of A is: %d",a); getch(); }
Value of A is: 10
hash (#) symbol is called pre-processor and include called directives. Both together called pre-processor directives.
#include
Both together also called file inclusion macro. Macro are nothing but a peace of code or block of code, which use to execute the peace of code or block of code before the main function using pre-processor directives.
Header file which end with (.h) extension and which contains predefine function declaration.
#include(stdio.h);
#include(conio.h);
#define is another pre-processor directives to create the own macro's or peace of code.
In C we have two type's declaration. Declaring a variable or a function called declaration.
Declaring a variable inside the function or within the block called local declaration, whose scope is within the function.
fun() { int a = 10; printf(" %d ",a); } fun1() { }
In above example fun1() cannot access the variable "a" because the scope of variable is within the block or within the function.
Declaring a variable outside the function called global declaration, whose scope is outside the function and inside the function.
int a = 10; fun() { } fun1() { }
In above example variable "a" declared as a global variable and both function can access the global variable.
Every program will have main function. main function is the entry point of the program execution. When we execute the program, compiler first execute the main function.
User define function also called subroutine function. It is define by the user. 1, 2, 3 section are optional.