469,142 Members | 1,109 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,142 developers. It's quick & easy.

What is the difference in these pointer assignements?

3 Bit
Const int * my_pointer= h

int * const my_pointer = h

2 Weeks Ago #1
2 1808
9,208 Expert Mod 8TB
Start with the pointer name and read backwards:

Const int* my_pointer etc...

my_pointer is a pointer (the *) to an int that is const.

Int * const my_pointer etc...

my_pointer.is a const pointer to an int that is not const.
2 Weeks Ago #2
489 Expert 256MB
To rephrase and add

const int * my_pointer= h
Contents of my_pointer i.e. elements of h are constant.

int * const my_pointer = h
my_pointer is constant, but not the contents.

If you happen to see const int * const my_pointer = h, both my_pointer and its contents are constant.

Use the variables in a program to understand better.
1 Week Ago #3

Post your reply

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

Similar topics

4 posts views Thread by Carsten Spieß | last post: by
3 posts views Thread by Bruno van Dooren | last post: by
35 posts views Thread by tuko | last post: by
16 posts views Thread by junky_fellow | last post: by
204 posts views Thread by Alexei A. Frounze | last post: by
16 posts views Thread by aegis | last post: by
23 posts views Thread by bluejack | last post: by
69 posts views Thread by fieldfallow | last post: by
27 posts views Thread by Erik de Castro Lopo | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.