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
What is the difference between far and near in c?
Why do we need a structure?
What is the difference between array and linked list in c?
Why is sizeof () an operator and not a function?
Is struct oop?
What is the difference between struct and union in C?
How do you override a defined macro?
Explain what is the difference between functions getch() and getche()?
What is the difference between exit() and _exit() function?
Explain how do you print an address?
What are external variables in c?
Write a function that will take in a phone number and output all possible alphabetical combinations
Explain what is wrong with this statement? Myname = ?robin?;
What is malloc calloc and realloc in c?
What does s c mean in text?