Pointer Variable

How to declare and initialize a pointer variable?

Questions by kakarukoireng

Showing Answers 1 - 6 of 6 Answers

For any type T:

T *p;           // declares p as a pointer to T
T *ap[N];    // declares ap as an N-element array of pointer to T
T (*pa)[N];  // declares pa as a pointer to an N-element array of T
T *fp();        // declares fp as a function returning a pointer to T
T (*pf)();     // declares pf as a pointer to a function returning T

For any lvalue x of type T, the expression "&x" yields a pointer to T:

int i = 1;
int *p = &i;

For any N-element array a of type T

  Was this answer useful?  Yes

Argh, hit "Submit" before I was finished.

For an array a of type T, the expression "&a" yields a pointer to an array of T:

int a[5] = {1,2,3,4,5};
int (*pa)[5] = &a;

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions