how to get started with pointers of c language and how can i get a good grip on them ?
Pointers
Collapse
X
-
Just read more than one book on C.
Pointers aren't as bad as they seem.
This is easy:
This creates an int variable named x;Code:int x;
Then:
This creates two int variables named x and y.Code:int x,y;
Now the good part:
This creates three variables. x and y are int. And *c is also an int.Code:int x,y,*c;
c is a pointer to an int. To see the int you must use *c to dereference c. Use the * dereference operator. c will refer to an int by containing the address of the int:
Then:Code:int x = 10; printf("%d", x); you will see 10
This last printf can print any int as long as the address of that int has been put into c. So now you can write one function that will print any int rather than a separate function for each int. The pointer lets you get around the name of the int.Code:int x = 10; int *c; there is no address of an int in c c = &x put the address of x into c printf("%d", *c); you will see 10
But beware: At all times c must contain the address of the correct int before you use c. You are responsible to see this happens.
Write a few simple programs and try this out.
Post again for more info.
Comment