+ 1

For the Code Below Please someone explain How the value of variable 'number' bcame 64 when we print it for the second time?

#include <iostream> using namespace std; void square(int&ptr){ ptr=ptr * ptr; } int main() { int number=8; cout<<number<<endl; square(number); cout<<number; return 0; any help is appreciated..thank you }

7th Apr 2018, 1:43 PM
RiGeL
RiGeL - avatar
1 Antwort
+ 2
The & in the square function says that modifications on ptr are also done on number.
7th Apr 2018, 1:51 PM
Timon Paßlick