Structure of a “C” program

Hello guys are you all ready for a ride in the world of C programming ???




Lets start our journey!!!!!

Here is an example for ‘C’:-

/*Write a program to print HELLO WORLD*/



Now we start form the top line, which starts /*.................*/.this symbols is called Documentation section. It is used for comment.

# include<stdio.h>
and  #include<conio.h> is called PRE PROCESSOR DIRECTIVES or statement.
PRE PROCESSOR DIRECTIVES starts with “#“.
Pre-processor program is a program process the source program before the control is given to the compiler.
Void main is called the function definition. Which tells the main() function.
“{......}” is the body of the main function. “{ “This symbol’s meaning is start of main function and” } ” this symbol’s meaning is end of the program.
Printf() is used to print data on the screen.
“ \n ” is called is a newline character, used for control to the next line.
All the statements must be terminated by semicolon “ ; ” symbol.

Header file:-
In above program, <stdio.h> is called header file. In <stdio.h>, ‘std’ means standard, ‘io’ means input- output header file. And <conio.h> means consol input- output header file. all the functions and variables we are useing in program are included in header files. Header file is a dictionary of program. 
In ‘C’ language, all the library functions are divided into their function in header file.
Some examples of header files are:-
-->math.h for using mathematically functions.
-->String.h for using string processing functions.
-->Conio.h for using console input-output functions.
In program  printf(),scanf() is included in <stdio.h>. when we use printf scanf  function, <stdio.h> must be included.

KEYWORDS and IDENTIFIERS:-

KEYWORDS are called reserved words. Because it’s meaning was fixed. KEYWORDS value does not change.

For example: char, double, short, int, return, register, far, for, goto, float, while, continue, switch etc.

IDENTIFIERS are used in program for convert program into easy form. It is define by the programmer. KEYWORDS cannot be used as IDENTIFIERS. Identifiers is like variables, functions etc. In IDENTIFIERS, underscore (‘_’) valid latter and first character written in an alphabet.
VARIABLES:-

In the program, variables are defined by the programmer. So it is a one type of identifier.
Which is used whose value changes as the program. Variables are declared in the program, when start of the main function (‘{‘) then it is declared.

For example:-

*/........................................../*
#include<stdio.h>
#include<conio.h>
Void main ()
{
int a, b, c;
 ...............................
....................
}.
We can use any number or latter for variable but variables must be starts with a latter.

 DATA TYPES:-

Generally DATA TYPES are four types:-










This Data Types are main types. Other types are also included into the ‘C’ program.

As shown in figure:-




Data Types are written in program before the variables.

The syntax is-
                    
data types var1, var2,.....varN;

Examples are:-

Int number;
Float average;
Char a;


When values are including in the program, syntax is different.

Syntax of variable with value:-

Variable name = value;

So    syntax with data type is

Data type variable name = value;
 

examples are:-

int a=5;
int b=7;

Symbolic Constants:-

When any constant is used in a program, that we need to change every statement when that constants occurs the program. These constants written above the function and below the pre-processor directives.

Syntax is :               #define symbolic_name value
Example:                #define PI 3.14

Here, there is no semicolon (’ ;’) at the end.     

Now we will write two example of the ‘C’ program for solve our confusion.

write a program to sum of two numbers



when we run the program (ctrl+F9), we will see the blank screen on the display and when we enter any values of “ a “ and “ b ”, output of sum will be “ c=a+b ” form. In this program, we have no fix values of “ a ” and “ b ” . So we entered values from outside(keyboard) and we scan values with         “ scanf ” function. scanf function is used for “ input ” and printf function is used for “ output “.
Lets see another program, but in this program we have fixed values.

Write a program to find sum of two numbers.


       
In this program, we have fix values of “a” and “b”. So we could not write scanf function and direct entered values of “a ”and “ b ”.
 So conclusion is when we have no values of any variable, we have to use “ printf ” and “ scanf ”  function to print any value on the screen from outside(keyboard) and when we have some fix values, we do not use “printf ” and “scanf ” function and direct write what we gain from the program  including fix values.

printf and scanf  both are main functions and much used in “C” but how to write printf and scanf statement?  here is:-

printf syntax is : printf(“Control String”, Name of Variables);
scanf syntax is:- scanf(“Control String”, Name of Address of Variables);


An example for “ printf ” is :-

float avg=10.3;
printf(“ average=%f\n”,avg);

An example of “ scanf ” is:-

int a;
printf(“enter value of a”);
scanf(“%d”,&a);

In scanf , when we enter integer values, “%d” is include in control string.
 For character values,”%c” is included in control string. For floating values, “%f” is included.

The intention of this post is to provide you a basic foundation of C. 
So guys my next post will be on various operators in C .

Untill then BYE BYE!!!!

To  like our facebook page  click here  NewAgeInformers 
To subscribe our youtube channel click here wolfpack

Comments