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 does c value mean?
Do you know null pointer?
how to execute a program using if else condition and the output should enter number and the number is odd only...
Why can’t we compare structures?
Is it possible to initialize a variable at the time it was declared?
What is dynamic memory allocation?
What is int main () in c?
What is the role of this pointer?
How to write a multi-statement macro?
Can include files be nested?
Write a program to print “hello world” without using semicolon?
Why doesnt that code work?
Write a program to check palindrome number in c programming?
What are the different data types in C?
provide an example of the Group by clause, when would you use this clause