In C, everything we write comes under a statement. A C program contains many number of statements. These are the building blocks of your C program.
Every Statement is ended up with a semicolon(;) except for the directives i.e., declared with the pre-processor (#).
For example,
Consider another example,
Every Statement is ended up with a semicolon(;) except for the directives i.e., declared with the pre-processor (#).
For example,
x=2+3;is a normal statement which adds up the values 2 and 3 and place the resulting value into the variable x.
White Spaces in Statements:
In C, generally white spaces are not considered into account. This means that, if a statement consists of white spaces, it ignores all the spaces and takes the statement.
For example,
x = 2 + 3 ;is similar to
x=2+3;This provides a flexibility for us to write the code easily. We can also write the code to be as
x=
2
+
3
;But this is not a good practice to write like this.
Consider another example,
printf(
"Hello World"
);is a valid presentation, but we can't split up the String literal
printf("Hello
World");If we want to split up like that, we have to place a backslash('\') while separating and split the string.
printf("Hello \
world");
Null Statements:
Null Statements are those which doesn't have anything in them. Sometimes we need to write such a statements to fulfill the syntax. Suppose, in a for loop, we don't have any initialization condition, then we place a null statement and proceed. Null Statement is nothing but an empty statement.
For example,
;
Compound Statements:
Compound Statements are the statements which are represented in the blocks of statements. In C, we write the blocks of the statements in between the curly braces ({....}). All the statements represented under the opening and closing braces comes under one section. These are local to that block of statements.
For example,
{
x=2+3;
printf("In the block");
}Thus we represent the compound statements.