Which of the following is illegal in C++? Question options: char answers [3]; char answers[3] = {'A','B','A'}; char teacher_name[20] = "Mrs. Smith"; char teacher_name[20]; teacher_name = "Mrs. Smith";
@Data_LG2
It's C?
I mean D
It's D.
In C++ the value of an array will be the memory address where the block of bytes of the array is allocated at. A string "some string" is implicitly also an array, and seemingly the value returned from it is the memory address where the bytes of the string are. So given 2 arrays means we have two different blocks of memory. We can copy the contents of the bytes between them, but what's done here is direct assignment of the address.. It makes no sense to assign one block to another, because you can't just change the address of the allocated bytes of the array... It would make sense to make such an assignment if you were assigning into a pointer instead, because that's the purpose of pointers, to hold memory addresses. So yes, that's right, D.
@pitamar An array is not a memory address to the block. It is actually a pointer to the first element. A pointer will never point to a block of memory.
|dw:1447956002963:dw|
Join our real-time social learning platform and learn together with your friends!