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

Question 1 of 10

Question 2 of 10

2. What is the correct syntax to declare a function foo() which receives an array of structure in function?

Question 2 of 10

Question 3 of 10

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

    #include <stdio.h>
    struct p
    {
        char *name;
        struct p *next;
    };
    struct p *ptrary[10];
    int main()
    {
        struct p p, q;
        p.name = "xyz";
        p.next = NULL;
        ptrary[0] = &p;
        strcpy(q.name, p.name);
        ptrary[1] = &q;
        printf("%s\n", ptrary[1]->name);
        return 0;
    } 

Question 3 of 10

Question 4 of 10

4. Which of the following is an incorrect syntax to pass by reference a member of a structure in a function?

(Assume: struct temp{int a;}s;)

Question 4 of 10

Question 5 of 10

5. Comment on the following declaration.

    int (*ptr)(); // i)
    char *ptr[]; // ii)

Question 5 of 10

Question 6 of 10

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

    #include <stdio.h>
    typedef struct p *q;
    struct p
    {
        int x;
        char y;
        q ptr;
    };
    int main()
    {
        struct p p = {1, 2, &p};
        printf("%d\n", p.ptr->x);
        return 0;
    } 

Question 6 of 10

Question 7 of 10

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

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

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. What will be the output of the following C code (run without any command line arguments)?

    #include <stdio.h>
    int main(int argc, char *argv[])
    {
        while (*argv  !=  NULL)
        printf("%s\n", *(argv++));
        return 0;
    } 

Question 9 of 10

Question 10 of 10

10. One of the uses for function pointers in C is __________

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.