Interview Questions

C/C++ Questions only (Arrays and Pointers)

C++ programming on UNIX, C++ Networking,C++ Algorithm Questions and Answers


(Continued from previous question...)

C/C++ Questions only (Arrays and Pointers)

1. I had the definition char a[6] in one source file, and in another

I declared extern char *a. Why didn't it work?

2. But I heard that char a[] was identical to char *a.

3. So what is meant by the ``equivalence of pointers and arrays'' in

C?

4. Why are array and pointer declarations interchangeable as function

formal parameters?

5. How can an array be an lvalue, if you can't assign to it?

6. What is the real difference between arrays and pointers?

7. Someone explained to me that arrays were really just constant

pointers.

8. I came across some ``joke'' code containing the ``expression''

5["abcdef"] . How can this be legal C?

9. What's the difference between array and &array?

10. How do I declare a pointer to an array?

11. How can I set an array's size at compile time?

12. How can I declare local arrays of a size matching a passed-in

array?

13. How can I dynamically allocate a multidimensional array?

14. Can I simulate a non-0-based array with a pointer?

15. My compiler complained when I passed a two-dimensional array to a

function expecting a pointer to a pointer.

16. How do I write functions which accept two-dimensional arrays when

the ``width'' is not known at compile time?

17. How can I use statically- and dynamically-allocated

multidimensional arrays interchangeably when passing them to

functions?

18. Why doesn't sizeof properly report the size of an array which is

a parameter to a

(Continued on next question...)

Other Interview Questions