C Programming Questions and Answers on Multidimensional Arrays for Freshers

1. 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);
Answer: a
2. Applications of multidimensional array are?

a) Matrix-Multiplication
b) Minimum Spanning Tree
c) Finding connectivity between nodes
d) All of the mentioned
Answer: d
3. What is the output of this C code?
  1.     #include 
  2.     int main()
  3.     {
  4.         int ary[2][3];
  5.         foo(ary);
  6.     }
  7.     void foo(int *ary[])
  8.     {
  9.         int i = 10, j = 2, k;
  10.         ary[0] = &i;
  11.         ary[1] = &j;
  12.         *ary[0] = 2;
  13.         for (k = 0;k < 2; k++)
  14.         printf("%d\n", *ary[k]);
  15.     }
a) 2 2
b) Compile time error
c) Undefined behaviour
d) 10 2
Answer: a
4. What is the output of this C code?
  1.     #include 
  2.     int main()
  3.     {
  4.         int ary[2][3];
  5.         foo(ary);
  6.     }
  7.     void foo(int (*ary)[3])
  8.     {
  9.         int i = 10, j = 2, k;
  10.         ary[0] = &i;
  11.         ary[1] = &j;
  12.         for (k = 0;k < 2; k++)
  13.         printf("%d\n", *ary[k]);
  14.     }
a) Compile time error
b) 10 2
c) Undefined behaviour
d) segmentation fault/code crash
Answer: a
5. What is the output of this C code?
  1.     #include 
  2.     int main()
  3.     {
  4.         foo(ary);
  5.     }
  6.     void foo(int **ary)
  7.     {
  8.         int i = 10, k = 10, j = 2;
  9.         int *ary[2];
  10.         ary[0] = &i;
  11.         ary[1] = &j;
  12.         printf("%d\n", ary[0][1]);
  13.     }
a) 10
b) 2
c) Compile time error
d) Undefined behaviour
Answer: d
6. What is the output of this C code?
  1.     #include 
  2.     int main()
  3.     {
  4.         int ary[2][3][4], j = 20;
  5.         ary[0][0] = &j;
  6.         printf("%d\n", *ary[0][0]);
  7.     }
a) Compile time error
b) 20
c) Address of j
d) Undefined behaviour
Answer: a
7. What is the output of this C code?
  1.     #include 
  2.     int main()
  3.     {
  4.         int ary[2][3];
  5.         ary[][] = {{1, 2, 3}, {4, 5, 6}};
  6.         printf("%d\n", ary[1][0]);
  7.     }
a) Compile time error
b) 4
c) 1
d) 2
Answer: a
8. What is the output of this C code?
  1.     #include 
  2.     void main()
  3.     {
  4.         int a[2][3] = {1, 2, 3, 4, 5};
  5.         int i = 0, j = 0;
  6.         for (i = 0; i < 2; i++)
  7.         for (j = 0; j < 3; j++)
  8.         printf("%d", a[i][j]);
  9.     }
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
Answer: a
9. What is the output of this C code?
  1.     #include 
  2.     void main()
  3.     {
  4.         int a[2][3] = {1, 2, 3, , 4, 5};
  5.         int i = 0, j = 0;
  6.         for (i = 0; i < 2; i++)
  7.         for (j = 0; j < 3; j++)
  8.         printf("%d", a[i][j]);
  9.     }
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
Answer: b
10. What is the output of this C code?
  1.     #include 
  2.     void f(int a[][3])
  3.     {
  4.         a[0][1] = 3;
  5.         int i = 0, j = 0;
  6.         for (i = 0; i < 2; i++)
  7.         for (j = 0; j < 3; j++)
  8.         printf("%d", a[i][j]);
  9.     }
  10.     void main()
  11.     {
  12.         int a[2][3] = {0};
  13.         f(a);
  14.     }
a) 0 3 0 0 0 0
b) Junk 3 junk junk junk junk
c) Compile time error
d) All junk values
Answer: a
11. What is the output of this C code?
  1.     #include 
  2.     void f(int a[][])
  3.     {
  4.         a[0][1] = 3;
  5.         int i = 0, j = 0;
  6.         for (i = 0;i < 2; i++)
  7.         for (j = 0;j < 3; j++)
  8.         printf("%d", a[i][j]);
  9.     }
  10.     void main()
  11.     {
  12.         int a[2][3] = {0};
  13.         f(a);
  14.     }
a) 0 3 0 0 0 0
b) Junk 3 junk junk junk junk
c) Compile time error
d) All junk values
Answer: c
12. What is the output of this C code?
  1.     #include 
  2.     void f(int a[2][])
  3.     {
  4.         a[0][1] = 3;
  5.         int i = 0, j = 0;
  6.         for (i = 0;i < 2; i++)
  7.         for (j = 0;j < 3; j++)
  8.         printf("%d", a[i][j]);
  9.     }
  10.     void main()
  11.     {
  12.         int a[2][3] = {0};
  13.         f(a);
  14.     }
a) 0 3 0 0 0 0
b) Junk 3 junk junk junk junk
c) Compile time error
d) All junk values
Answer: c
13. 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
Answer: b
14. Comment on the 2 arrays regarding P and Q:
  1. int *a1[8];
  2.     int *(a3[8]);
  3.     P. Array of pointers
  4.     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
Answer: b
15. Which of the following is not possible statically in C?

a) Jagged Array
b) Rectangular Array
c) Cuboidal Array
d) Multidimensional Array
Answer: a

Related

C Programming Questions and Answers on Pointers to Pointers for Freshers

1. What is the output of this C code? #include void main() { int k = 5; int *p = &k; int **m = &p; printf("%d%d%d\n", k, *p, **m);...

Java Multiple Choice Questions & Answers on Serialization for Freshers

1. Which of these is a process of writing the state of an object to a byte stream? a) Serializationb) Externalizationc) File Filteringd) All of the mentioned Answer: a Explanation: Serialization ...

CSS Multiple Choice Questions & Answers on Major Themes for Freshers

1. _____________ property specifies the direction in which a marquee should move. a) marquee-styleb) marquee-play-countc) marquee-directiond) none of the mentioned Answer: c Explanation: Syntax: ...

Post a Comment

emo-but-icon
:noprob:
:smile:
:shy:
:trope:
:sneered:
:happy:
:escort:
:rapt:
:love:
:heart:
:angry:
:hate:
:sad:
:sigh:
:disappointed:
:cry:
:fear:
:surprise:
:unbelieve:
:shit:
:like:
:dislike:
:clap:
:cuff:
:fist:
:ok:
:file:
:link:
:place:
:contact:

item