pointers

Started by
10 comments, last by cleves 20 years, 1 month ago
1) is completely wrong, but I can see how 2) and 3) have some justification.

text is the value of the pointer - the address of the string literal. << just happens to be overloaded so that the string is printed, instead of its address. std::cout << (void*)text <<std::endl; would display the pointer value itself.

&text is the address of the text pointer - it''s a char**. There is some ambiguity as tho whether "the Address of the Text" referred to the text variable, or the string literal.

*text is the value of the pointee, not the value of the pointer.

“Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.” — Brian W. Kernighan (C programming language co-inventor)
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Advertisement
char text[] = "This is an array of characters, notice the [].\n";
cout << text << endl;

This topic is closed to new replies.

Advertisement