Essential Information C
Essential Information C
3. Decision statements:
It checks the given condition and then executes its sub-block. The decision statement decides the
statement to be executed after the success or failure of a given condition.
Types:
1. If statement
2. If-else statement
Statements, syntaxes and examples of If statement and if else statement are shown in figure
3.
1
statement syntax example operators
If statement if(condition) if(a>b) > (relational)
Statement; {
s=a; = (assignment)
}
If-else if (condition) if(a>b) > (relational)
statement { {
Statements; s=a; = (assignment)
} }
else else
{ {
Statements; s=b;
} }
Figure 3
4. Loop control statements
Loop is a block of statements which are repeatedly executed for certain number of times.
Description of for loop and while loop are shown in figure 4.
Types:
1. For loop
2. While loop
statement syntax example
for loop for(initialize counter; test condition; re-evaluation parameter) for(i=0;i<=10;i++)
{ {
Statement; s=i+1;
Statement; }
}
while loop While (test condition) while(a==b)
{ {
Body of the loop a=a+1;
} }
Figure 4
5. Arrays
In C, an array is formed by laying out all the elements contiguously in memory. The square
bracket syntax can be used to refer to the elements in the array. The array as a whole is referred to
by the address of the first element which is also known as the "base address" of the whole array.
Graphical representation of array is shown in figure 5.
{
int arr[6];
int sum = 0;
sum += array[0] + array[1];
}
arr