My Report

C Programming Practice Test 2


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 *p = NULL;
        for (foo(); p; p = 0)
            printf("In for loop\n");
            printf("After loop\n");
    } 

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

    #include <stdio.h>
    switch (ch)
    {
       case 'a':
       case 'A':
          printf("true");
    } 

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

    #include 
    int main()
    {
        for (int i = 0;i < 1; i++)
            printf("In for loop\n");
    } 

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

    #include <stdio.h>
    int x;
    void main()
    {
        if (x)
            printf("hi");
        else
            printf("how are u");
    } 

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

    #include <stdio.h>
    int main()
    {
        int x = 0;
        if (x == 1)
            if (x >= 0)
                printf("true\n");
            else
                printf("false\n");
    } 

6. Which function in the following expression will be called first?

a = func3(6) - func2(4, 5) / func1(1, 2, 3);

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>
    int main()
    {
        switch (printf("Do"))
        {
           case 1:
              printf("First\n");
              break;
           case 2:
              printf("Second\n");
              break;
           default:
              printf("Default\n");
              break;
        }
    } 

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

    #include 
    int main()
    {
        do
            printf("In while loop ");
        while (0);
            printf("After loop\n");
    } 

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

    #include <stdio.h>
    int main()
    {
        printf("%d ", 1);
        l1:l2:
        printf("%d ", 2);
        printf("%d\n", 3);
    } 

 

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.