Home / C Programming / Control Structures :: control structures

C Programming :: Control Structures

  1. Find the output of the following program.

    #include<stdio.h>

    void main()

    {

    int y=10;

    if(y++>9 && y++!=10 && y++>11)

    printf("%d", y);

    else

    printf("%d", y);

    }

  2. A.

     11

    B.

     12

    C.

     13

    D.

     14

    E.

     Compilation error

    View Answer

    Workspace

    Discuss Discuss in Forum


  3. What will be the value of sum after the following program is executed?

    void main()

    {

    int sum=1, index = 9;

    do{

    index = index – 1;

    sum *= 2;

    }while( index > 9 );

    }

  4. A.

     1

    B.

     2

    C.

     9

    D.

     0.5

    E.

     0.25

    View Answer

    Workspace

    Discuss Discuss in Forum


  5. What is the right choice, if the following loop is implemented?

    void main()

    {

    int num = 0;

    do{

    --num;

    printf("%d", num);

    }while( ++num >= 0 );

    }

  6. A.

     A run time error will be generated.

    B.

     The program will not enter into the loop.

    C.

     There will be a compilation error reported.

    D.

     The loop will run infinitely many times.

    E.

     Prints the value of 0 one time only.

    View Answer

    Workspace

    Discuss Discuss in Forum


  7. What will be the final value of the digit?

    void main()

    {

    int digit = 0;

    for( ; digit <= 9; )

    digit++;

    digit *= 2;

    --digit;

    }

  8. A.

     -1

    B.

     17

    C.

     19

    D.

     16

    E.

     20

    View Answer

    Workspace

    Discuss Discuss in Forum


  9. What will be the following code's output if choice = 'R'?

    switch(choice)

    {

    case 'R' : printf("RED");

    case 'W' : printf("WHITE");

    case 'B' : printf("BLUE");

    default : printf("ERROR");break;

    }

  10. A.

     RED

    B.

     RED WHITE BLUE ERROR

    C.

     RED ERROR

    D.

     RED WHITE BLUE

    E.

     ERROR

    View Answer

    Workspace

    Discuss Discuss in Forum


  11. Consider the following program fragment:

    for(c=1, sum=0; c <= 10; c++)

    {

    scanf("%d", &x);

    if( x < 0 ) continue;

    sum += x;

    }

    What would be the value of sum for the input 1, -1, 2, -2, 3, -3, 4, -4, 5, -5

  12. A.

     -5

    B.

     30

    C.

     10

    D.

     1

    E.

     15

    View Answer

    Workspace

    Discuss Discuss in Forum


  13. What will be printed if the following code is executed?

    void main()

    {

    int x=0;

    for( ; ; )

    {

    if( x++ == 4 ) break;

    continue;

    }

    printf("x=%d", x);

    }

  14. A.

     x=0

    B.

     x=5

    C.

     x=4

    D.

     x=1

    E.

     Error

    View Answer

    Workspace

    Discuss Discuss in Forum


  15. Consider the following code:

    void main()

    {

    int a[5] = {6,8,3,9,0}, i=0;

    if(i != 0)

    {

    break;

    printf("%d", a[i]);

    }

    else

    printf("%d", a[i++]);

    }

    What is the output of the above program?

  16. A.

     6

    B.

     8

    C.

     Runtime error

    D.

     Syntax error

    E.

     No output

    View Answer

    Workspace

    Discuss Discuss in Forum