Frequently asked questions C language

  1. Difference between conditional and looping statement

Conditional statement executes only once in the program where as looping statements executes repeatedly several number of time.

  1. What is a nested loop?

A nested loop is a loop that runs within another loop. Put it in another sense, you have an inner loop that is inside an outer loop. In this scenario, the inner loop is performed a number of times as specified by the outer loop. For each turn on the outer loop, the inner loop is first performed.

  1. When is a “switch” statement preferable over an “if” statement?

The switch statement is best used when dealing with selections based on a single variable or expression. However, switch statements can only evaluate integer and character data types.

  1. Why we use do-while loop in c? Also tell any properties which you know?

It is also called as post tested loop. It is used when it is necessary to execute the loop at least one time. Syntax:

do {

Loop body

} while (Expression);

Example:

int main(){

int num,i=0;

do{

printf(“To enter press 1\n”);

printf(“To exit press  2”);

scanf(“%d”,&num);

++i;

switch(num){

case 1:printf(“You are welcome\n”);break;

default : exit(0);

}

}

while(i<=10);

return 0;

}

Output: 3 3 4 4

  1. What is the use of “goto” statement?

goto statement is used to transfer the normal flow of a program to the specified in the program. Below is the syntax for goto statement in C.

{

……..

goto label;

……

…….

LABEL:

Statements;

}

  1. What is the output of this C code?

int main()

{

int a = 0, i = 0, b;

For (i = 0;i < 5; i++)

{

a++;

Continue;

}

}

Output:5