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; }

25th Aug 2018, 12:26 AM
Faisal Hamman Adama Muhammad
Faisal Hamman Adama Muhammad - avatar
4 Respostas
0
yeah
25th Aug 2018, 12:59 AM
Faisal Hamman Adama Muhammad
Faisal Hamman Adama Muhammad - avatar
0
a general question
25th Aug 2018, 1:38 AM
Faisal Hamman Adama Muhammad
Faisal Hamman Adama Muhammad - avatar
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...
25th Aug 2018, 2:19 AM
Ketan Lalcheta
Ketan Lalcheta - avatar