Using Pointer in C

Now this is not your definitive guide to using pointer, it's more of a "i hope i won't forget this" kinda guide intended for yours truly.

To use pointer, you need to make sure you have 3 things:-

1. The pointer must be declared and allocated.
2. The pointee must be declared and allocated.
3. The pointer (1) must be initialized so that it points to the pointee (3).

Example;

int *p //step 1.
int i //step 2.

p = &i; //step 3.

*p = 42 //now you can use...

The important thing to remember is that when you declare something as a pointer - like p for instance, the value in p would be an address pointing to somewhere; so if let say you'd do a printf of p - you'll be shown the address of i, not the value of i.

Comments

Popular posts from this blog

HIVE: Both Left and Right Aliases Encountered in Join

Assign select result to variable in Netezza stored procedure

Splitting value in Netezza using array_split