B20: problem in C++ pointer
swe sd
ccwork@hotmail.com
Sat Mar 11 09:31:00 GMT 2000
I compiled the following program (attachment test.cc):
line 1: #include <iostream>
line 2: void main()
line 3: { const int size=10;
line 4: int A[size];
line 5: int *X=NULL, i;
line 6: for (i=0;i<size;i++) A[i]=i;
line 7: cout<<A[0]<<" "<<&A<<" "<<&A[0]<<endl;
line 8: X=A;
line 9: cout<<A[0]<<" "<<&A<<" "<<&A[0]<<endl
line 10: <<*X<<endl
line 11: <<*X+5<<endl
line 12: <<*X<<" "<<A[0]<<endl
line 13: <<5+X[0]<<endl
line 14: <<( X[0]==0 ? "X[0]=0" : "X[0]!=0")<<endl
line 15: <<++X[0]<<endl
line 16: }
and executing it gives output:
$./a.out
0 0x259fd7c 0x259fd7c
1 0x259fd7c 0x259fd7c
1
6
1 1
6
X[0]!=0
1
Obviously, the output of line 9 is different from line 7 which should be
the same indeed. Is there anything wrong ? Thanks.
______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: cygcheck.out
Type: text/x-algol68
Size: 6323 bytes
Desc: not available
URL: <http://cygwin.com/pipermail/cygwin/attachments/20000311/dfd5d0fe/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.cc
Type: text/x-c
Size: 467 bytes
Desc: not available
URL: <http://cygwin.com/pipermail/cygwin/attachments/20000311/dfd5d0fe/attachment-0001.bin>
More information about the Cygwin
mailing list