I was solving a quiz and this is a question:
Which of the following gives the memory address of the first element in array foo, an array with 100 elements?
A. foo[0];
B. foo;
C. &foo;
D. foo[1];
Both foo and &foo gives the same result. Which one is true?
Thanks
I believe they want "foo"
Given that this is quick...
A. foo[0];
This will dereference the pointer to the first element of the array 'foo'.
B. foo;
This will return the address of the start of the array 'foo' and is permitted to be NULL.
C. &foo;
This will return the address of the start of the array 'foo' and is not permitted to be NULL. Array 'foo' must either be allocated or statically declared, or pointing to another valid variable of some kind that isn't NULL.
Google 'references versus pointers in C'.
D. foo[1];
This will dereference the second element of the array.
Thanks for answer. Nice to have answer.
I have a question, you said permited to be NULL; could you make it clear please. Thanks
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks