My Report

C Programming Practice Test 6


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. The conversion characters d, i, o, u, and x may be preceded by h in scanf() to indicate?

2. When a C program is started, O.S environment is responsible for opening file and providing pointer for that file?

3. Bit fields can only be declared as part of a structure.

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

    #include <stdio.h>
    int main()
    {
        int i = 10, j = 3;
        printf("%d %d %d", i, j);
    } 

5. What will be the output of the following C code if following commands are used to run (considering myfile exists)?

    gcc -otest test.c
    ./test < myfile

    #include <stdio.h>
    int main()
    {
        char c = 'd';
        putchar(c);
    } 

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

    #include <stdio.h>
    #include <stdarg.h>
    int f(int c, ...);
    int main()
    {
        int c = 97;
        float d = 98;
        f(c, d);
        return 0;
    }
    int f(int c, ...)
    {
        va_list li;
        va_start(li, c);
        float d = va_arg(li, float);
        printf("%f\n", d);
        va_end(li);
    } 

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

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

8. What is typedef declaration?

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

    #include <stdio.h>
    int main()
    {
        char buf[12];
        stderr = stdin;
        fscanf(stderr, "%s", buf);
        printf("%s\n", buf);
    }

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

    #include <stdio.h>
    int main()
    {
        int i = 10, j = 3;
        printf("%d %d %d", i, j);
    } 

 

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.