Welcome to MSDN Blogs Sign in | Join | Help
Slang - 'C' - Lang (for beginners)

Hello Guys,

Sorry again if the title is misleading, but how often pointers have been more like a slang to a beginner. I can bet there are more nods right now!! I am middle of studying deeper into Templates, but I just found enough time to talk about Pointers (and constants).

This is supposed to be a small topic and I promise to keep it that way.Lets start right away..

int const *x;
int * const x;

Lets break it and lemme(did I use sms language) show you how to interpret that..

Block A-----Block B------Block C-----Block D
    int           const      *(pointer)        x

    int         *(pointer)      const          x

 

Reading sequence would be Block D->Block B-> Block C-> Block A

Let me show you what I am trying to say.

1) x(starting from Block D) is a constant (now in Block B) pointer (moving to Block C) to int (moving back to Block A)

Lets go in the same way for second one..

2) Remember, we would start from Block D, jump to Block B move to  Block C and then move to Block A..so lets start.

x is a Pointer to constant int.

 

Great, now that we have learnt how to read this, lets see what these actually mean...

1) Let me repeat "Constant pointer to int". Now looks relatively simpler, isint it? 

  1. Pointer is of type int
  2. Constant pointer, so the address it is referencing, cannot be changed (the value its pointing to can be changed). 

2) "Pointer to constant int"

  1. Pointer is pointing to int
  2. Its a pointer to a constant value. So the value that address is pointing to, cannot be changed (the address itself can be changed).

 

I hope now pointers and constants make more sense to you. Please do leave comments. If I sneak once more, I would edit this and add some coding examples. Good bye till then.

Posted: Monday, May 12, 2008 1:29 AM by gouravdas
Filed under: , ,

Comments

No Comments

Leave a Comment

(required) 

(required) 

(optional)

(required) 

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Page view tracker