What is statement in C with example ?

 A statement in C is block (single or multiple lines) of code that causes the computer to carry out some action.


There are different classes of statement in c , they are 

1. Expression statement 

2. Compound statement

3. Control statement

Expression statement

An expression statement consists of an expression followed by semicolon , when these statements are executed by computer an evaluation occurs.

a = 3;
It is an assignment expression.

c = a + b;
This expression adds a and b and assign it to c.

Compound statement

A compound statement consists of several individual elements enclosed with in braces { }.

The individual statement may themselves be expression or compound or control statement.

Unlike expression statement it doesn't end with semicolon .

example

{
pi = 3.14;
circumference = 2 * pi * radius;
area = pi * radius * radius ;
}

Control statement

Control statements are used to create special program features such as logical tests , loops  and branches , many control statement composed of other statement like expression and compound statement.

An example is given below.

while ( count < = n ) {

printf( "X = ");
scanf( "%d" ,&x ) ;
sum += x;
++count;

}

we will learn about control statements later in details.




Contact Form

Name

Email *

Message *