Statement

Statement

Published by: Nuru

Published date: 21 Jun 2021

Statement Photo

Statement

A statement is a complete direction instructing the computer to carry out some task. In C, statements are usually written one per line, although some statements can span multiple lines. A statement consists of expression, literals, and other variables. C statements always end with a semicolon (except for preprocessor directives such as #define and #include)

  • For example: x = 2 + 3; is an assignment statement. It instructs the computer to add 2 and 3 and to assign the result to the variable x.
  • printf(“C Programming”); - is a output statement

 

The C compiler isn't sensitive to white space. When the compiler reads a statement in the source code, it ignores white space.

Thus, the statement

  • x=5+6;
  • x =    5 + 6;
  • x        = 5 + 6;

All are equivalent

Note: But Within literal string constants, tabs and spaces aren't ignored; they are considered part of the string.

For example

in “C   Programming   Language”  -the spaces also part of string not ignored.

  • Literal string constants are strings that are enclosed within quotes and interpreted literally by the compiler, space for space.
  • Although it's extremely bad form, the following is legal:

print(

"Hello world!"

);

However,printf("Hello, world!" );  is not legal

The reason is to break a literal string constant line, we must use the backslash character (\) just before the break.

Thus, the following is legal:

printf("Hello,\ world!");

 

Null Statement

If we place a semicolon by itself on a line, we create a null statement i.e. a statement that doesn't perform any action. This is perfectly legal in C.

e.g.  the null statement is:            ;

Compound Statement

A compound statement, also called a block, is a group of two or more C statements enclosed in braces. Here's an example of a block:

{

printf("Hello, ");

printf("world!");

}

In C, a block can be used anywhere a single statement can be used. Note that the enclosing braces can be positioned in different ways. The following is equivalent to the preceding example:

{printf("Hello, "); printf("world!");}

 

Comments

Comments are those parts of the source code which are ignored by the compiler during compilation.
In C, comments are anything written between the characters /* and */

e.g. /* This is my First C Program */

If multiple lines comments are needed, we can use multiple comments each per one line or multi-line single comment using the same starting and ending characters.

e.g.:
/*this is my first c program

to print hello world

*/

Expression

In C, an expression is anything that evaluates to a numeric value. C expressions come in all levels of complexity inside a statement.

Simple Expression

The simplest C expression consists of a single item: a simple variable, literal constant, or symbolic constant.

Here are three expressions with description
1) PI - A symbolic constant (defined in the program)
2) 20 - A literal constant rate A variable
3)1.25 - Another literal constant

Note:
• A literal constant evaluates to its own value.
• A symbolic constant evaluates to the value it was given when we created it using the #define directive or in const statement
• A variable evaluates to the current value assigned to it by the program.

Complex Expression

Statements with Complex expressions consist of simpler expressions connected by operators. For example:

6 + 8 is an expression consisting of the sub-expressions 6 and 8 and the addition operator +. The expression 6 + 8 evaluates 14

We can also write C expressions of great complexity:
1.25 / 8 + 5 * rate + rate * rate / cost

Consider a statement: x = a + 10;

  1.  This statement evaluates the expression a + 10 and assigns the result to variable x.
  2. In addition, the entire statement x = a + 10 is itself an expression that evaluates to the value of the variable on the left side of the equal sign.

Example

/* A C program to pring Hello world */
#include /* Std input output header file */

#include

main() / * main function */
{

printf(“Hello world”);

getch();

return 0;
}

output:

Hello world