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
How does struct work in c?
Why do we use static in c?
What are pointers really good for, anyway?
.find the output of the following program? char*myfunc(char*ptr) { ptr +=3; return (ptr); } int main() { char*x,*y; x="HELLO"; y=myfunc(x); printf("y = %s ",y); return 0; }
What is memcpy() function?
What should malloc(0) do? Return a null pointer or a pointer to 0 bytes?
An integer that indentifies the position of a data item in a sequence of data items a) value b) number c) index d) all of the above
Explain about C function prototype?
Which driver is a pure java driver
What’s a signal? Explain what do I use signals for?
Why C language is a procedural language?
What is nested structure?
What are the two forms of #include directive?
Does c have function or method?
What is a void pointer? When is a void pointer used?