C Programming -Pointers Vs. Multi-dimensional Arrays

C Programming-Multidimensional Arrays

Question 1
What is the output of this C code?
        #include 
        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]);
        }
A
1 2 3 4 5 0
B
1 2 3 4 5 junk
C
1 2 3 4 5 5
D
Run time error
Question 2
What is the output of this C code?
        #include 
        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]);
        }
A
1 2 3 junk 4 5
B
Compile time error
C
1 2 3 0 4 5
D
1 2 3 3 4 5
Question 3
What is the output of this C code?
        #include 
        void f(int a[][3])
        {
        a[0][1] = 3;
        int i = 0, j = 0;
        for (i = 0; i < 2; i++)
        for (j = 0; j < 3; j++)
        printf("%d", a[i][j]);
        }
        void main()
        {
        int a[2][3] = {0};
        f(a);
        }
A
0 3 0 0 0 0
B
Junk 3 junk junk junk junk
C
Compile time error
D
All junk values
Question 4
What is the output of this C code?
        #include 
        void f(int a[][])
        {
        a[0][1] = 3;
        int i = 0, j = 0;
        for (i = 0;i < 2; i++)
        for (j = 0;j < 3; j++)
        printf("%d", a[i][j]);
        }
        void main()
        {
        int a[2][3] = {0};
        f(a);
        }
A
0 3 0 0 0 0
B
Junk 3 junk junk junk junk
C
Compile time error
D
All junk values
Question 5
What is the output of this C code?
        #include 
        void f(int a[2][])
        {
        a[0][1] = 3;
        int i = 0, j = 0;
        for (i = 0;i < 2; i++)
        for (j = 0;j < 3; j++)
        printf("%d", a[i][j]);
        }
        void main()
        {
        int a[2][3] = {0};
        f(a);
        }
A
0 3 0 0 0 0
B
Junk 3 junk junk junk junk
C
Compile time error
D
All junk values
Question 6
Comment on the following statement:     int (*a)[7];
A
An array “a” of pointers.
B
A pointer “a” to an array.
C
A ragged array.
D
None of the mentioned
Question 7
 Comment on the 2 arrays regarding P and Q:     int *a1[8];     int *(a3[8]);     P. Array of pointers     Q. Pointer to an array
A
a1 is P, a2 is Q
B
a1 is P, a2 is P
C
a1 is Q, a2 is P
D
a1 is Q, a2 is Q
Question 8
 Which of the following is not possible statically in C?
A
Jagged Array
B
Rectangular Array
C
Cuboidal Array
D
Multidimensional Array
Question 9
What is the correct syntax to send a 3-dimensional array as a parameter?    (Assuming declaration int a[5][4][3];)
A
func(a);
B
func(&a);
C
func(*a);
D
func(**a);
Question 10
Applications of multidimensional array are?
A
Matrix-Multiplication
B
Minimum Spanning Tree
C
Finding connectivity between nodes
D
All of the mentioned
Question 11
What is the output of this C code?
    #include 
    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]);
    }
A
2 2
B
Compile time error
C
Undefined behaviour
D
10 2
Question 12
What is the output of this C code?
    #include 
    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]);
    }
A
Compile time error
B
10 2
C
Undefined behaviour
D
segmentation fault/code crash
Question 13
What is the output of this C code?
    #include 
    int main()
    {
    foo(ary);
    }
    void foo(int **ary)
    {
    int i = 10, k = 10, j = 2;
    int *ary[2];
    ary[0] = &i;
    ary[1] = &j;
    printf("%d\n", ary[0][1]);
    }
A
10
B
2
C
Compile time error
D
Undefined behaviour
Question 14
What is the output of this C code?
    #include 
    int main()
    {
    int ary[2][3][4], j = 20;
    ary[0][0] = &j;
    printf("%d\n", *ary[0][0]);
    }
A
Compile time error
B
20
C
Address of j
D
Undefined behaviour
Question 15
What is the output of this C code?
    #include 
    int main()
    {
    int ary[2][3];
    ary[][] = {{1, 2, 3}, {4, 5, 6}};
    printf("%d\n", ary[1][0]);
    }
A
Compile time error
B
4
C
1
D
2


Check Your Answers:

  1. A
  2. B
  3. A
  4. C
  5. C
  6. B
  7. B
  8. A
  9. A
10. D
11. A
12. A
13. D
14. A
15. A

 
SHARE

Unknown

  • Image
  • Image
  • Image
  • Image
  • Image
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment