+ 2

What it the output of this code and why?

char* a = "test"; cout << *(a+5);

14th Nov 2016, 9:16 PM
Freddy Alexander Paredes
Freddy Alexander Paredes - avatar
2 odpowiedzi
+ 3
It should throw an error, for three reasons: 1. You defined it as a char, and then made it a string. 2. You can't add a string and an integer 3. You make the pointer point to (a+5) where it should just be a So, I'm not sure that it'll work at it's current state.
14th Nov 2016, 10:04 PM
Keto Z
Keto Z - avatar
+ 2
i saw this on an challenge :/
19th Nov 2016, 11:24 AM
Freddy Alexander Paredes
Freddy Alexander Paredes - avatar