+ 1
why is the answer 17 in the following code
#include <iostream> using namespace std; int main() { int x = 5; int *p = &x; x = x + 4; x = *p + 4; *p = *p + 4; cout << x << endl << x << endl << *p << endl; return 0; } please help me!
2 Antworten
+ 10
p = &x means *p = x
So, the core of the code is:
x = x + 4
x = x + 4
x = x + 4
meaning
x = 5 + 4 = 9
x = 9 + 4 = 13
x = 13 + 4 = 17
That's why the output is 17 17 17.
0
thank you for your answer!