Tuesday, September 27, 2011

pointer in c++

in C or C++,when we declare a variable like int x;we define normal variable with type int,but when we declare like int* y,or int *y,that means we declare a int pointer
we assign int value to x as normal
int x;
x = 100;
but for pointer,we assign like this
y = &x; //that means y will contains x's address
if we print *y ,that means we print value of x,because * get object of that pointer point to.
here is a table that summarize all of those operators



expressioncan be read as
*xpointed by x
&xaddress of x
x.ymember y of object x
x->ymember y of object pointed by x
(*x).ymember y of object pointed by x (equivalent to the previous one)
x[0]first object pointed by x
x[1]second object pointed by x
x[n](n+1)th object pointed by x

No comments:

Post a Comment