My Report

C Programming Practice Test 5


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>
    struct p
    {
        int x;
        int y;
    };
    int main()
    {
        struct p p1[] = {1, 2, 3, 4, 5, 6};
        struct p *ptr1 = p1;
        printf("%d %d\n", ptr1->x, (ptr1 + 2)->x);
    } 

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

    #include <stdio.h>
    void f(int);
    void (*foo)(float) = f;
    int main()
    {
        foo(10);
    }
    void f(int i)
    {
        printf("%d\n", i);
    } 

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

    #include <stdio.h>
    struct p
    {
        int x[2];
    };
    struct q
    {
        int *x;
    };
    int main()
    {
        struct p p1 = {1, 2};
        struct q *ptr1 = (struct q*)&p1;
        ptr1->x = (struct q*)&p1.x;
        printf("%d\n", ptr1->x[0]);
    } 

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

    #include <stdio.h>
    void main()
    {
        struct student
        {
            int no;
            char name[20];
        };
        struct student s;
        s.no = 8;
        printf("%d", s.no);
    } 

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

    #include <stdio.h>
    struct p
    {
        int x;
        char y;
    };
    typedef struct p* q*;
    int main()
    {
        struct p p1[] = {1, 92, 3, 94, 5, 96};
        q ptr1 = p1;
        printf("%d\n", ptr1->x);
    } 

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

    #include <stdio.h>
    struct
    {
        int k;
        char c;
    } p;
    int p = 10;
    int main()
    {
        p.k = 10;
        printf("%d %d\n", p.k, p);
    } 

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

    #include <stdio.h>
    int mul(int a, int b, int c)
    {
        return a * b * c;
    }
    void main()
    {
        int (function_pointer)(int, int, int);
        function_pointer = mul;
        printf("The product of three numbers is:%d",
        function_pointer(2, 3, 4));
    } 

8. How many bytes in memory taken by the following C structure?

    #include <stdio.h>
    struct test
    {
        int k;
        char c;
    }; 

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

    #include <stdio.h>
    struct student
    {
        char *c;
        struct student *point;
    };
    void main()
    {
        struct student s;
        struct student *m = &s;
        printf("%d", sizeof(student));
    } 

10. What is argv[0] in command line arguments?


 

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.