472,096 Members | 1,290 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,096 software developers and data experts.

What is the difference in these pointer assignements?

3 Bit
Const int * my_pointer= h

int * const my_pointer = h

Sep 10 '21 #1
2 4737
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.
Sep 10 '21 #2
624 Expert 512MB
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.
Sep 13 '21 #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
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.