wats the diference btwen constant pointer and pointer to a
constant.pls give examples.

Answer Posted / satyajit nayak

Hello All,
AS name suggested things are very simple.
1.Constant pointer
======================
it's nothing but a
(i)pointer which is pointing to a constant memory
location.
(ii)Once this pointer is assigned to point some location
we cann't make it to locate some other address location.
(iii)So constant pointer should be initialized at the
point of declaration only.

Example
=========
1. int main()
{
int * const my_ptr; //now my_ptr point to garbage
location
int var=10;
my_ptr=&var; //trying to modify my_ptr location.so
gives ERROR
}
so correct way of assignment is like
int main()
{
int var=10;
int * const my_ptr=&var;
printf("Addr=%x,val=%d",my_ptr,*my_ptr);
}

Is This Answer Correct ?    8 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

why we wont use '&' sing in aceesing the string using scanf

1777


write a program to convert a expression in polish notation(postfix) to inline(normal) something like make 723+* (2+3) x 7 (not sure) just check out its mainly printing expression in postfix form to infix.

2264


What is mean by Data Driven framework in QTP? Can any one answer me in details on this regard.

1781


How old is c programming language?

571


What is the equivalent code of the following statement in WHILE LOOP format?

763






What does p mean in physics?

581


What is New modifiers?

665


Why is c called a mid-level programming language?

720


What is the use of getchar() function?

624


write a program to copy the string using switch case?

2398


how many errors in c explain deply

1627


Is there a way to have non-constant case labels (i.e. Ranges or arbitrary expressions)?

574


What are the similarities between c and c++?

593


Explain how are portions of a program disabled in demo versions?

649


how to write optimum code to divide a 50 digit number with a 25 digit number??

2747