What is the difference between constant to pointer and pointer to constant?

Questions by sachinp1979   answers by sachinp1979

Showing Answers 1 - 2 of 2 Answers

laxmikanth_rajuri

  • Feb 25th, 2006
 

Constant pointer:If a pointer is pointing to a constant whose value(constant)can't be changed.

Eg:Consider the declaration int a[10];

here a is a pointer to the base address of the array say 1000.When we try to modify  a value say a++ or a-- it will give error because a is a constant pointer to the array.

pointer constant:If a pointer doesn't to points to any variable,array,structure,object,structure,etc...such pointer is known as pointer constant.

Eg:The well known example for pointer constant is the predefine Macro NULL.

NULL is a pointer constant which doesn't to points to any thing. 

  Was this answer useful?  Yes

pointer to constant: If a pointer is pointing to constant it is called as pointer to constant.In this case we cannot change the content of constant.

eg :  const int n=5;

  int *p=&n;

in this case we cannot change the value of n.

constant pointer:  If we declare a pointer as constant we can change the contents of memory pointed by pointer.But we cannot change the pointer value i.e incrementing or decrementing of pointer address.

Eg : const int *p=n;

Here we can change the content of n,but we cannot increment or decrement of pointer p(p++ or ++p).

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions