My Report

C Programming Practice 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. Which of the following typecasting is accepted by C?

2. 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;
    } 

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

    #include <stdio.h>
    int main()
    {
        int a = 1, b = 1, c;
        c = a++ + b;
        printf("%d, %d", a, b);
    }

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

    #include <stdio.h>
    int main()
    {
        if (~0 == 1)
            printf("yes\n");
        else
            printf("no\n");
    } 

5. What will be the output of the following C code considering the size of a short int is 2, char is 1 and int is 4 bytes?

    #include <stdio.h>
    int main()
    {
        short int i = 20;
        char c = 97;
        printf("%d, %d, %d\n", sizeof(i), sizeof(c), sizeof(c + i));
        return 0;
    } 

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

    #include <stdio.h>
    void main()
    {
        int x = 1, z = 3;
        int y = x << 3;
        printf(" %d\n", y);
    } 

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

    #include <stdio.h>
    int main()
    {
        enum {ORANGE = 5, MANGO, BANANA = 4, PEACH};
        printf("PEACH = %d\n", PEACH);
    }

8. What is the precedence of arithmetic operators (from highest to lowest)?

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

    #include <stdio.h>
    int main()
    {
        int x = -2;
        x = x >> 1;
        printf("%d\n", x);
    } 

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

    #include <stdio.h>
    void main()
    {
        int x = 97;
        int y = sizeof(x++);
        printf("x is %d", x);
    } 

 

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.