My Report

C Programming Mock Test 4


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>
    void main()
    {
        int k = 5;
        int *p = &k;
        int **m  = &p;
        **m = 6;
        printf("%d\n", k);
    }

Question 1 of 10

Question 2 of 10

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

    #include <stdio.h>
    void main()
    {
        int a[2][3] = {1, 2, 3, 4, 5};
        int i = 0, j = 0;
        for (i = 0; i < 2; i++)
        for (j = 0; j < 3; j++)
        printf("%d", a[i][j]);
    } 

Question 2 of 10

Question 3 of 10

3. Which of the following arithmetic operation can be applied to pointers a and b?
(Assuming initialization as int *a = (int *)2; int *b = (int *)3;)

Question 3 of 10

Question 4 of 10

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

    #include <stdio.h>
    int main()
    {
        char **p = {"hello", "hi", "bye"};
        printf("%s", (p)[0]);
        return 0;
    } 

Question 4 of 10

Question 5 of 10

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

    #include <stdio.h>
    int main()
    {
        char *str = "hello, world\n";
        str[5] = '.';
        printf("%s\n", str);
        return 0;
    } 

Question 5 of 10

Question 6 of 10

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

    #include <stdio.h>
    int *f();
    int main()
    {
        int *p = f();
        printf("%d\n", *p);
    }
    int *f()
    {
        int *j = (int*)malloc(sizeof(int));
        *j = 10;
        return j;
    }

Question 6 of 10

Question 7 of 10

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

    #include <stdio.h>
    void main()
    {
        #define max 45
        max = 32;
        printf("%d", max);
    } 

Question 7 of 10

Question 8 of 10

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

    #include <stdio.h>
    void main()
    {
        int a[3] = {1, 2, 3};
        int *p = a;
        int *r = &p;
        printf("%d", (**r));
    }

Question 8 of 10

Question 9 of 10

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

    #include <stdio.h>
    int main()
    {
        char *str = "hello world";
        char strary[] = "hello world";
        printf("%d %d\n", sizeof(str), sizeof(strary));
        return 0;
    } 

Question 9 of 10

Question 10 of 10

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

    #include <stdio.h>
    int main()
    {
        void *p;
        int a[4] = {1, 2, 3, 8};
        p = &a[3];
        int *ptr = &a[2];
        int n = p - ptr;
        printf("%d\n", n);
    } 

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.