Why does it output ow from how? | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
+ 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; }

26th Mar 2017, 7:18 AM
nabeer zahed chowdhury
nabeer zahed chowdhury - avatar
1 Antwort
+ 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"
26th Mar 2017, 7:32 AM
देवेंद्र महाजन (Devender)
देवेंद्र महाजन (Devender) - avatar