My Report

C Programming Mock 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
 10%

Question 1 of 10

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, 92, 3, 94, 5, 96};
        struct p *ptr1 = p1;
        int x = (sizeof(p1) / 5);
        if (x == 3)
            printf("%d %d\n", ptr1->x, (ptr1 + x - 1)->x);
        else
            printf("false\n");
    } 

Question 1 of 10

Question 2 of 10

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

    #include <stdio.h>
    struct point
    {
        int x;
        int y;
    };
    void foo(struct point*);
    int main()
    {
        struct point p1[] = {1, 2, 3, 4};
        foo(p1);
    }
    void foo(struct point p[])
    {
        printf("%d\n", p->x);
    } 

Question 2 of 10

Question 3 of 10

3. Which of the following uses structure?

Question 3 of 10

Question 4 of 10

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

    #include <stdio.h>
    struct student fun(void)
    {
        struct student
        {
            char *name;
        };
        struct student s;
        s.name = "alan";
        return s;
    }
    void main()
    {
        struct student m = fun();
        printf("%s", m.name);
    } 

Question 4 of 10

Question 5 of 10

5. Which of the following operation is illegal in structures?

Question 5 of 10

Question 6 of 10

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

    #include <stdio.h>
    struct student
    {
        char *name;
    };
    struct student fun(void)
    {
        struct student s;
        s.name = "alan";
        return s;
    }
    void main()
    {
        struct student m = fun();
        printf("%s", m.name);
    } 

Question 6 of 10

Question 7 of 10

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

    #include <stdio.h>
    struct student
    {
    };
    void main()
    {
        struct student s[2];
        printf("%d", sizeof(s));
    } 

Question 7 of 10

Question 8 of 10

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

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

Question 8 of 10

Question 9 of 10

9. Which of the following is an incorrect syntax for pointer to structure?

(Assuming struct temp{int b;}*my_struct;)

Question 9 of 10

Question 10 of 10

10. 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]);
    } 

Question 10 of 10


 

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.