Char *a="12345"; Char*b=++a; Cout<< *++b; Explain me this code | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4

Char *a="12345"; Char*b=++a; Cout<< *++b; Explain me this code

4th Feb 2020, 1:36 AM
Manoj
Manoj - avatar
4 Answers
+ 10
When you preincrement a using ++a, you effectively move the pointer to the next character('2') in the string. The address of this char is also assigned to b which is a second char pointer. In the third line, b is incremented further to point to the next char ('3'). The * in front is used to dereference the pointer to get the actual character value and this is then inserted into the standard output stream which effectively prints '3' on the console screen.
4th Feb 2020, 1:57 AM
Sonic
Sonic - avatar
+ 4
char is a character data type. char* is a pointer to a character which can also be the first character in an array or string of characters like "12345".
4th Feb 2020, 1:51 AM
Sonic
Sonic - avatar
+ 2
It's char and not chat.
4th Feb 2020, 1:49 AM
Sonic
Sonic - avatar
+ 2
Ok thanks got it
4th Feb 2020, 2:09 AM
Manoj
Manoj - avatar