C Programming Questions and Answers – Pointers Vs. Multi-dimensional Arrays – 1

«
»
This section on C programming questions and answers focuses on “Pointers Vs. Multi-dimensional Arrays”. One shall practice these questions to improve their C programming skills needed for various interviews (campus interviews, walkin interviews, company interviews), placements, entrance exams and other competitive exams. These questions can be attempted by anyone focusing on learning C Programming language. They can be a beginner, fresher, engineering graduate or an experienced IT professional. Our C programming questions come with detailed explanation of the answers which helps in better understanding of C concepts.

Here is a listing of C programming questions on “Pointers Vs. Multi-dimensional Arrays” along with answers, explanations and/or solutions:

1. Which is true for a, if a is defined as “int a[10][20];”?
a) a is true two-dimensional array
b) 200 int-sized locations have been set aside
c) The conventional rectangular subscript calculation 20 * row + col is used to find the element a[row, col].
d) All of the mentioned
View Answer

Answer: d
Explanation: None.
advertisement

2. Which is true for b, if b is defined as “int *b[10];”?
a) The definition only allocates 10 pointers and does not initialize them
b) Initialization must be done explicitly
c) The definition only allocates 10 pointers and does not initialize them & Initialization must be done explicitly
d) Error
View Answer

Answer: c
Explanation: None.

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

advertisement
advertisement
  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         char a[10][5] = {"hi", "hello", "fellows"};
  5.         printf("%s", a[2]);
  6.     }

a) fellows
b) fellow
c) fello
d) fell
View Answer

Answer: c
Explanation: Since every row in the array a[10][5] can contain only 5 characters, the a[2] element will hold “fello” i.e. 5 characters. There will not be any null character in a[2]. Since, the array is completely intialized, other rows (row a[3] will have only null characters. Hence, printf() using %s specifier will display fello only.
advertisement

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

  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         char a[10][5] = {"hi", "hello", "fellows"};
  5.         printf("%p\n", a);
  6.         printf("%p", a[0]);
  7.     }

a) same address is printed
b) different address is printed
c) hello
d) hi hello fello
View Answer

Answer: a
Explanation: None.
advertisement

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

advertisement
  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         char a[10][5] = {"hi", "hello", "fellows"};
  5.         printf("%d", sizeof(a[1]));
  6.     }

a) 2
b) 4
c) 5
d) 10
View Answer

Answer: c
Explanation: None.

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

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         char a[1][5] = {"hello"};
  5.         printf("%s", a[0]);
  6.         return 0;
  7.     }

a) Compile time error
b) hello
c) Undefined behaviour
d) hellon
View Answer

Answer: c
Explanation: None.

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

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         char *a[1] = {"hello"};
  5.         printf("%s", a[0]);
  6.         return 0;
  7.     }

a) Compile time error
b) hello
c) Undefined behaviour
d) hellon
View Answer

Answer: b
Explanation: None.

8. Which of the following statements are true?

    P. Pointer to Array
    Q. Multi-dimensional array

a) P are static, Q are static
b) P are static, Q are dynamic
c) P are dynamic, Q are static
d) P are dynamic, Q are dynamic
View Answer

Answer: c
Explanation: None.

Sanfoundry Global Education & Learning Series – C Programming Language.

Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

advertisement
advertisement

Leave a Comment

Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer & SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage, Advanced C Programming, SAN Storage Technologies, SCSI Internals & Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him @ LinkedIn | Youtube | Instagram | Facebook | Twitter