Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
C++
+ const int* var = &v
+ int const* var = &v
+ const int *const var = &v


What I have tried:

what is the difference between this ?
Posted
Updated 17-Dec-20 0:36am

Try the documentation: c const pointer - Google Search[^]
 
Share this answer
 
C
const int* var = &v; // var is a pointer to const int, it is initialized with v address
int const* var = &v; // var is a pointer to const int, it is initialized with v address
const int *const var = &v; // var is a const pointer to const int, initialized with v address
So, while the first two definitions are interchangeable, the third is a bit different.

You may easily verify yourself using cdecl: C gibberish ↔ English[^]
 
Share this answer
 
Comments
Richard MacCutchan 17-Dec-20 6:43am    
+5; good link.
CPallini 17-Dec-20 7:34am    
Thank you and have my 5 as well.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900