If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2008-02-17
Perhaps I'm wrong but that seem home work at all.
int m = 44; // a integer initiated to 44
int p = &m; // pointer-to-int initiated with the address of m (p point-to-m)
int &r = m; // a reference (alias) to m
int n = (p)++; // a int inititated to unary increment of the deference of p = m++ = 45
int q = p -1; / a pointer-to-int initiated with...
Here is the trickery. here you decrease the value of the p pointer
and q points to some place undefined in your code. From this point
your code is trash.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have a really simple code
include <iostream>
using namespace std;
int main()
{
int m = 44;
int p = &m;
int &r = m;
int n = (p)++;
int q = p -1;
r = (--p) + 1;
++ *q;
cout << m;
system("pause");
}
and i get the output
2291613
Can someone please explain why i get this output?
thanks for the help
Perhaps I'm wrong but that seem home work at all.
int m = 44; // a integer initiated to 44
int p = &m; // pointer-to-int initiated with the address of m (p point-to-m)
int &r = m; // a reference (alias) to m
int n = (p)++; // a int inititated to unary increment of the deference of p = m++ = 45
int q = p -1; / a pointer-to-int initiated with...
Here is the trickery. here you decrease the value of the p pointer
and q points to some place undefined in your code. From this point
your code is trash.