Note 1

Take Note:

Take a note while surfing.





Note With Ink

Give your Note a Colorful Tag.




Easy to Access

Stay on same information and in Sync wherever you are.

Note 2

Take Note:

Organize your information,It may take Shape.





Think With Ink

Differ your Content by Color.




Easy to Access

Easy to pull up your content from anywhere anytime.

Note 3

Take Note:

Don't Let information to miss,Because it take shape





Note With Ink

Simple an Easy Way to take a note.




Easy to Access

Get the same in next visit.


Please wait...

C Programming :: Control Instructions

Home > C Programming > Control Instructions > General Questions

1. What is the output of the following 'C' program?

#include
void main()
{
int i=3;

switch(i)
{
default:printf("zero");
case 1: printf("one");
break;
case 2:printf("two");
break;
case 3: printf("three");
break;
}
}

View Answer | Discuss in Forum | Workspace | Asked In |

Answer: Option B

Explanation:

The default case can be placed anywhere inside the loop. It is executed only when all other cases doesn't match.

Workspace


Tags:  No Tags on this question yet!

2. What is the output of the following 'C' program?

#include
main()
{
int i=1,j=2;
switch(i)
{
case 1: printf("GOOD");
break;
case j: printf("BAD");
break;
}
}

View Answer | Discuss in Forum | Workspace | Asked In |

Answer: Option A

Explanation:

The case statement can have only constant expressions (this implies that we cannot use variable names directly so an error).

Workspace


Tags:  No Tags on this question yet!

3. What is the output of the following 'C' program?

#include
void main()
{
int i=10,j=20;
j=i,j?(i,j)?i:j:j;
printf("%d %d",i,j);
}

View Answer | Discuss in Forum | Workspace | Asked In |

Answer: Option A

Explanation:

  1. notice the comma operator when variables are separated by them they are evaluated from left to right and only last value is considered ( it has less precedence than assignment operator)
    so due to the precedence of assignment being high the assignment is done first and then comma operator is evaluated be the expression finally evaluates to j=i,(j?(i,j)?i:j:j);
  2. so the value of i is assigned to j
    you can run the same program  with one more variable C the value of j will be equal to the value of C as per above logic

#include

void main()

{

int i=10,j=20;

int c=10000;

j=c,j?(i,j)?i:j:j;

printf("%d %d",i,j);

}


Workspace


Tags:  No Tags on this question yet!

4. What is the output of the following 'C' program?

#include
void main()
{
float i=1.5;
switch(i)
{
case 1: printf("1");
case 2: printf("2");
default : printf("0");
}
}

View Answer | Discuss in Forum | Workspace | Asked In |

Answer: Option C

Explanation:

Switch statements can be applied only to integral types.

Workspace


Tags:  No Tags on this question yet!

5. How many times "Nagarro" will get printed?

#include
int main()
{
int x;

for (x=-1; x<10;x++)
{
if (x<5)
continue;
else
break;
printf("Nagarro");
}
return 0;
}

View Answer | Discuss in Forum | Workspace | Asked In |

Answer: Option C

Explanation:

0 times as due to continue statement  the lower part of loop is ignored and next iteration continue when x is greater than or equal to 5  else part of loop execute and due to the break statement the loop terminates

Workspace


Tags:  nagarro

View Answer | Discuss in Forum | Workspace | Asked In |

Answer: Option A

Explanation:

Here is no explanation for this answer

Workspace


Tags:  nagarro

7. The type of the controlling statement of a switch statement cannot be of the type

View Answer | Discuss in Forum | Workspace | Asked In |

Answer: Option D

Explanation:

Here is no explanation for this answer

Workspace


Tags:  Wipro

8. What will be the O/P?

void main()
{
int i=0;
switch(i){
case 0 : printf("%d",i);break;
case 1 : printf("%d",i);break;
}
}

View Answer | Discuss in Forum | Workspace | Asked In |

Answer: Option B

Explanation:

Here is no explanation for this answer

Workspace


Tags:  Wipro

9. Given the following C program, which one of the alternatives is correct?

main()
{
char status;
int balance;
balance = 1000;
status= (balance>= 1000)? 'C': 'O'
}

View Answer | Discuss in Forum | Workspace | Asked In |

Answer: Option B

Explanation:

the ternary statement (condition)? value1 : value2 can be converted to a similar if else function as follow
    if(condition==true){

        return value1;

    else{
        return value2;

    }

so as per above logic the given ternary statement is converted as
    if(balance>=1000){

        return 'C';

    }else{

        return 'O';

    }    

Workspace


Tags:  No Tags on this question yet!

10. What is the output of the following program?

void main()
{
int B, X, Y, Z;
X=1; Y=2; Z=3;
jf ((X > 1) || (Y > 1))
if (Z > 1)
printf ("O.K /n");
else break;
if((X > 1 && (Z > 3))
printf ("Bye /n");
printf ("Hello!");
}

View Answer | Discuss in Forum | Workspace | Asked In |

Answer: Option A

Explanation:

Here is no explanation for this answer

Workspace


Tags:  No Tags on this question yet!