My Report

C Array Test – 2


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>
    void foo(int *ary[]);
    int main()
    {
        int ary[2][3];
        foo(ary);
    }
    void foo(int *ary[])
    {
        int i = 10, j = 2, k;
        ary[0] = &i;
        ary[1] = &j;
        *ary[0] = 2;
        for (k = 0;k < 2; k++)
        printf("%d\n", *ary[k]);
    } 

2. What is the correct syntax to send a 3-dimensional array as a parameter? (Assuming declaration int a[5][4][3];)

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

    #include <stdio.h>
    int main()
    {
        foo(ary);
    }
    void foo(int **ary)
    {
        int i = 10, k = 20, j = 30;
        int *ary[2];
        ary[0] = &i;
        ary[1] = &j;
        printf("%d\n", ary[0][1]);
    } 

4. What are the applications of a multidimensional array?

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

    #include <stdio.h>
    int main()
    {
        int ary[2][3][4], j = 20;
        ary[0][0] = &j;
        printf("%d\n", *ary[0][0]);
    } 

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

    #include <stdio.h>
    int main()
    {
        int ary[2][3];
        ary[][] = {{1, 2, 3}, {4, 5, 6}};
        printf("%d\n", ary[1][0]);
    } 

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

    #include <stdio.h>
    void foo(int (*ary)[3]);
    int main()
    {
        int ary[2][3];
        foo(ary);
    }
    void foo(int (*ary)[3])
    {
        int i = 10, j = 2, k;
        ary[0] = &i;
        ary[1] = &j;
        for (k = 0;k < 2; k++)
        printf("%d\n", *ary[k]);
    } 

 

Start practicing “1000 MCQs on C”, and once you are ready, you can take tests on all topics by attempting our “C Test Series”.

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.