4 Years
Discussion Span
Last Post by tenzinlol

A pointer is the address of a variable (or the address of an array slot, the address of a struct member etc.). For as long as the pointed-to variable is alive, you can access its value by dereferencing the pointer.


You could say that a pointer variable holds addresses ... adresses for any kind of 'object' ... including the address of an other pointer variable ... and in that case, you then have a 'pointer to a pointer'.

One very common use of pointers is when you allocate dynamic memory ... The pointer then holds the address to the first byte in that newly allocated memory.

How were you wanting to use pointers?

Can you supply some example code?

Edited by David W


it takes value of a vairable or only takes adress of vairable ??

pointer variable takes address of another variable which must be same as pointer type.you can't point float variable using pointer to int declaration.you must have pointer to float in this case.look below :

int* ptr;
int x=10;
float y;

ptr=&y; //Incorrect . Because ptr is pointer to int and it can't be used to point float.

ptr=&x //Correct. Because Both type are same.the statement will assign the address of x to pointer ptr
print *ptr //*ptr is de referencing(i.e. get the value at address)
*ptr=20 //set the value at address .Now x becomes 20

here is how you delcare a pointer
int *ptr;
let 'a' be a variable
int a;
The statement below takes the adderess of the variable a
where as the syntax given below takes the value of the variable

Edited by tenzinlol: wrong

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.