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

a sequence of bytes with one to one corrspondence to those in the external device a) sequential addressing b) address c) byte code d) none

725


What do you mean by a local block?

632


What is void pointers in c?

590


What is a scope resolution operator in c?

751


In c programming language, how many parameters can be passed to a function ?

631






Why is python slower than c?

606


Explain what is the best way to comment out a section of code that contains comments?

722


What is an lvalue in c?

696


Synonymous with pointer array a) character array b) ragged array c) multiple array d) none

616


Why is C language being considered a middle level language?

656


Dont ansi function prototypes render lint obsolete?

606


Was 2000 a leap year?

632


why use functions a) writing functions avoids rewriting the same code over and over b) using functions it becomes easier to write programs and keep track of what they are doing c) a & b d) none of the above

654


pgm to find any error in linklist(in single linklist check whether any node points any of previous nodes instead of next node)

2201


What is meant by inheritance?

634