By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,824 Members | 2,337 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,824 IT Pros & Developers. It's quick & easy.

Pointers

P: 1
how to get started with pointers of c language and how can i get a good grip on them ?
Dec 17 '17 #1
Share this Question
Share on Google+
2 Replies


weaknessforcats
Expert Mod 5K+
P: 9,197
Just read more than one book on C.

Pointers aren't as bad as they seem.

This is easy:

Expand|Select|Wrap|Line Numbers
  1. int x;
This creates an int variable named x;

Then:

Expand|Select|Wrap|Line Numbers
  1. int x,y;
This creates two int variables named x and y.

Now the good part:

Expand|Select|Wrap|Line Numbers
  1. int x,y,*c;
This creates three variables. x and y are int. And *c is also an int.

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:

Expand|Select|Wrap|Line Numbers
  1. int x = 10;
  2. printf("%d", x);  you will see 10
  3.  
Then:
Expand|Select|Wrap|Line Numbers
  1. int x = 10;
  2. int *c;           there is no address of an int in c
  3.  
  4. c = &x            put the address of x into c
  5.  
  6. printf("%d", *c);  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.

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.
Dec 17 '17 #2

P: 7
Pointers are all about & and * so the only way is to practice it like all other topics.
A pointer is easy but seems difficult at the start.
Use book by Denis Ritchie(creator of c language).
Feb 21 '18 #3

Post your reply

Sign in to post your reply or Sign up for a free account.