+ 4
Why does it output ow from how?
#include <iostream> using namespace std; int main() { char* word = "how"; cout << word++ << endl; cout << word; return 0; }
1 Answer
+ 3
1. char* word = "how";
A pointer to char named word is created with initial value "how".
Usually pointer to char datatype is used for creating variable length
strings. Initially pointer word points to the first character in the string.
2. cout << word++ << endl;
This statement prints the value of the string word. word++ will advance
the pointer reference to the next character in the string. Now the pointer
word refers to "ow"
3. cout << word;
This statement prints the remaining contents in the string i.e., "ow"