Search Placementyogi.com
 

C Basics Objective Questions

  :: Topics ::

3.

What's the difference between const char *p, char * const p and const char * const p?

A: 

const char *p    -   This is a pointer to a constant char. One cannot change the value pointed at by p, but can change the pointer p itself.

 

                     *p = 'A' is illegal.

                     p  = "Hello" is legal.

 

                     Note that even char const *p is the same!

 

const * char p   -   This is a constant pointer to (non-const) char. One cannot change the pointer p, but can change the value pointed at by p.

 

                     *p = 'A' is legal.

                     p  = "Hello" is illegal.

 

 

 

const char * const p  -   This is a constant pointer to constant char! One cannot change the value pointed to by p nor the pointer.

 

                          *p = 'A' is illegal.

                          p  = "Hello" is also illegal.

 

Preview

Thanks for posting your comment! It will be visible soon!
Post Another Comment

3
+
2
=

Name:
Email :
 

Banner to LogicGuns.com

Hide Page Information