0
What will be the output of the following program and why?
#include <iostream> using namespace std; int main(){ const int i = 20; const int* const ptr = &i; (*ptr)++; int j = 15; ptr = &j; cout << i; return 0; }
4 Respostas
0
yeah
0
a general question
0
Faisal Hamman Adama Muhammad it has compiler error and hence no output..
two errors are there.
1. (*ptr)++ tries to change value of i as ptr points to i.. on first line, you have declared i as constant and changing constant gives error
2. ptr =&j gives error as ptr is constant ( by declaring *const ptr ) and now you are trying to change it pointing from i to j...