wats the diference btwen constant pointer and pointer to a
constant.pls give examples.
Answer Posted / monika sethi
CONSTANT POINTER: A pointer will always point to one
object.it is initialized at the time of declaration.
e.g
int i=20,j;
int* const p=&i;
cout<<*p; //will print 20
*p=30;//works....i.e the value pointed by the constant
pointer can be changed
//now if write
p=&j;//error
POINTER TO CONSTANT
it can be declared as
const int *p;
or
int const *p;
int i=10,j=30;
p=&i;
cout<<*p;
*p=10//error...the value is constant pointed by p
//pointer p is not constant so it can now point to another
variable of integer type
//so if we write
p=&j //it will now point to a variable j
that's all.........
| Is This Answer Correct ? | 27 Yes | 0 No |
Post New Answer View All Answers
I heard that you have to include stdio.h before calling printf. Why?
Does c have enums?
What is the description for syntax errors?
What is an expression?
How is a pointer variable declared?
What is %lu in c?
What is the use of header?
Why do we write return 0 in c?
What is register variable in c language?
What is oops c?
What are pointers? What are different types of pointers?
How can I determine whether a machines byte order is big-endian or little-endian?
Explain what does the format %10.2 mean when included in a printf statement?
can we implement multi-threads in c.
How are Structure passing and returning implemented by the complier?