Saturday, 18 November 2017

C MCQ - Decision Control and Loop Control Structure

1. The output of the code below is
    #include <stdio.h>
    int a;
    void main()
    {
        if (a)
            printf("Hello");
        else
            printf("world");
    }
a) Hello
b) World 
c) compile time error
d) none of the mentioned


2. The output of the code below is


    #include <stdio.h>
    void main()
    {
        int a = 5;
        if (true);
            printf("hello");
    }
a) It will display hello
b) It will throw an error
c) No Output
d) Depends on Compiler


3. The output of the code below is

#include <stdio.h>
    void main()
    {
        int a = 0;
        if (a == 0)
            printf("hi");
        else
            printf("how are u");
            printf("hello");
    }
a) hi
b) how are you
c) hello
d) hihello


4. The following code ‘for(;;)’ represents an infinite loop. It can be terminated by.

a) break
b) exit(0)
c) abort()
d) all of the mentioned


5. The correct syntax for running two variable for loop simultaneously is.

a) for (i = 0; i < n; i++)
     for (j = 0; j < n; j += 5)
b) for (i = 0, j = 0;i < n, j < n; i++, j += 5)
c) for (i = 0; i < n;i++){}
d) for (j = 0; j < n;j += 5){}


6.  Which for loop has range of similar indexes of ‘i’ used in for (i = 0;i < n; i++)?

a) for (i = n; i>0; i--)
b) for (i = n; i >= 0; i--)
c) for (i = n-1; i>0; i--)
d) for (i = n-1; i>-1; i--)


7.  The output of this C code is?


    #include <stdio.h>
    void main()
    {
        int x = 0;
        for (x < 3; x++)
        printf("Hello");
    }
a) Compile time error
b) Hello is printed thrice
c) Nothing
d) Varies


8. The output of this C code is?


    #include <stdio.h>
    void main()
    {
        double x = 0;
        for (x = 0.0; x < 3.0; x++)
            printf("Hello");
    }
a) Run time error
b) Hello is printed thrice
c) Hello is printed twice
d) Hello is printed infinitely


9.  The output of this C code is?


    #include <stdio.h>
    int main()
    {
        do
            printf("Inside while loop ");
        while (0);
            printf("Outside loop\n");
    }
a) Inside while loop
b) Inside while loop
Outside loop
c) Outside loop
d) Infinite loop


10. The output of this C code is?

    #include <stdio.h>
    int main()
    {
        int i = 0;
        do {
            i++;
            printf("Inside while loop\n");
        } while (i < 3);
    }
a) Inside while loop
Inside while loop
Inside while loop
b) Inside while loop
Inside while loop
c) Depends on the compiler
d) Compile time error


11. Which of the following cannot be used as LHS of the expression in for (exp1 ;exp2 ; exp3) ?

a) Variable
b) Function
c) typedef
d) macros 


12. Which keyword can be used for coming out of recursion?

a) break
b) return
c) exit
d) Both break and return


13. The keyword ‘break’ cannot be simply used within:
a) do-while
b) if-else
c) for
d) while


14. Which keyword is used to come out of a loop only for single iteration?
a) break
b) continue 
c) return
d) none of the mentioned


15.  The output of this C code is?

    #include <stdio.h>
    void main()
    {
        int i = 0;
        if (i == 0)
        {
            printf("Hello");
            break;
        }
    }
a) Hello is printed infinite times
b) Hello
c) Varies
d) Compile time error 

1 comment:

  1. thank u so mucu please upload some more as soon as possible

    ReplyDelete

Featured Post

TCS Latest Test Patern ( For On-Campus Drives )

Tata Consultancy Services is software services consulting company whose  headquarter is situated in Mumbai, India. It is the Asia’s larges...