My Report

C Expression Test – 3


Correct Answer: 2 points | Wrong: -1 point
Grades: A* (100% score) | A (80%-99%) | B (60%-80%) | C (40%-60%) | D (0%-40%)
advertisement

1. What will be the output of the following C code?

    #include <stdio.h>
    int main()
    {
        int x = 2, y = 0, l;
        int z;
        z = y = 1, l = x && y;
        printf("%d\n", l);
        return 0;
    } 

2. What will be the output of the following C code?

    #include <stdio.h>
    int main()
    {
        int x = 2, y = 0;
        int z;
        z = (y++, y);
        printf("%d\n", z);
        return 0;
    } 

3. In expression i = g() + f(), first function called depends on __________

4. What will be the output of the following C function?

    #include <stdio.h>
    int main()
    {
        reverse(1);
    }
    void reverse(int i)
    {
        if (i > 5)
            exit(0);
        printf("%d\n", i);
        return reverse(i++);
    } 

5. What will be the final values of i and j in the following C code?

    #include <stdio.h>
    int x = 0;
    int f()
    {
        if (x == 0)
            return ++x;
        else
            return --x;
    }
    int g()
    {
        return x++;
    }
    int main()
    {
        int i, j;
        i = (f() + g()) || g();
        x = 0;
        j = g() || (f() + g());
    }

6. What will be the output of the following C code?

    #include <stdio.h>
    int main()
    {
        int x = 2, y = 0;
        int z = (y++) ? 2 : y == 1 && x;
        printf("%d\n", z);
        return 0;
    } 

7. What will be the final values of i and j in the following C code?

    #include <stdio.h>
    int x = 0;
    int f()
    {
        if (x == 0)
            return x + 1;
        else
            return x - 1;
    }
    int g()
    {
        return x++;
    }
    int main()
    {
        int i = (f() + g()) | g(); //bitwise or
        int j = g() | (f() + g()); //bitwise or
    } 

8. What will be the output of the following C function?

    #include <stdio.h>
    void reverse(int i);
    int main()
    {
        reverse(1);
    }
    void reverse(int i)
    {
        if (i > 5)
            return ;
        printf("%d ", i);
        return reverse((i++, i));
    } 

9. What will be the output of the following C code?

    #include <stdio.h>
    int main()
    {
        int x = 2, y = 0;
        int z = y && (y |= 10);
        printf("%d\n", z);
        return 0;
    } 

10. What will be the output of the following C code?

    #include <stdio.h>
    int main()
    {
        int y = 2;
        int z = y +(y = 10);
        printf("%d\n", z);
    } 

 

Start practicing “1000 MCQs on C”, and once you are ready, you can take tests on all topics by attempting our “C Test Series”.

Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.