My Report

C Expression Test – 1


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 = 1;
        int y =  x == 1 ? getchar(): 2;
        printf("%d\n", y);
    } 

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

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

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

    #include <stdio.h>
    void main()
    {
        1 < 2 ? return 1 : return 2;
    } 

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

    #include <stdio.h>
    int main()
    {
        int x = 1;
        short int i = 2;
        float f = 3;
        if (sizeof((x == 2) ? f : i) == sizeof(float))
            printf("float\n");
        else if (sizeof((x == 2) ? f : i) == sizeof(short int))
            printf("short int\n");
    } 

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

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

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

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

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

    #include <stdio.h>
    void main()
    {
        int k = 8;
        int m = 7;
        int z = k < m ? k++ : m++;
        printf("%d", z);
    } 

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

    #include <stdio.h>
    void main()
    {
        int k = 8;
        int m = 7;
        int z = k < m ? k = m : m++;
        printf("%d", 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.