[cs13001] L19 Question
Mikhail Nesterenko
mikhail at cs.kent.edu
Mon Oct 29 23:57:51 EDT 2012
>
1 > int *ip1, *ip2, one = 1, two = 2;
2 >
3 > ip1 = &one;
4 > ip2 = ip1;
5 > *ip1 = *ip1 + 1;
6 > ip1 = &two;
7 > *ip1 -= 1;
8 > cout << *ip2 << ' ' << *ip1 << endl;
>
> how exactly is the output of *ip2 equal to 2 ? I don't get it,
> shouldn't be equal to 1 like *ip1 ?
In line 5, both ip1 and ip2 point to variable "one", whose value by then
is 2
In line 6, ip1 starts pointing to variable "two". On line 7, the value
of this variable is decreased from 2 to 1.
Thanks,
--
Mikhail
More information about the cs13001
mailing list