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

«
»
Sanfoundry’s 1000+ Interview Questions & Answers on C helps anyone preparing for Intel and other companies C interviews. One should practice these 1000+ interview questions and answers continuously for 2-3 months to clear Intel interviews on C Programming language.

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

1. What will be the output of the following C code (considering sizeof char is 1 and pointer is 4)?

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

a) 9
b) 4
c) 8
d) 10
View Answer

Answer: c
Explanation: None.
advertisement
advertisement

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

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

a) 9
b) 12
c) 8
d) 10
View Answer

Answer: b
Explanation: None.
advertisement

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

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

a) hello
b) hi
c) ello
d) ello hi
View Answer

Answer: c
Explanation: None.
advertisement

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

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

a) hello
b) ello
c) hi
d) ello hi
View Answer

Answer: c
Explanation: None.

5. What is the advantage of a multidimensional array over pointer array?
a) Predefined size
b) Input can be taken from user
c) Faster Access
d) All of the mentioned
View Answer

Answer: d
Explanation: None.

6. Which of the following operation is possible using a pointer char? (Assuming the declaration is char *a;)
a) Input via %s
b) Generation of the multidimensional array
c) Changing address to point at another location
d) All of the mentioned
View Answer

Answer: c
Explanation: None.

7. Comment on the following two operations.

    int *a[] = {{1, 2, 3}, {1, 2, 3, 4}}; //- 1
    int b[4][4] = {{1, 2, 3}, {1, 2, 3, 4}};//- 2

a) 1 will work, 2 will not
b) 1 and 2, both will work
c) 1 won’t work, 2 will work
d) Neither of them will work
View Answer

Answer: c
Explanation: None.

8. Comment on the following two operations.

    int *a[] = {{1, 2, 3}, {1, 2, 3, 4}}; //- 1
    int b[][] = {{1, 2, 3}, {1, 2, 3, 4}}; //- 2

a) 1 works, 2 doesn’t
b) 2 works, 1 doesn’t
c) Both of them work
d) Neither of them work
View Answer

Answer: d
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