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
What is the use of static variable in c?
Why is not a pointer null after calling free? How unsafe is it to use (assign, compare) a pointer value after it is been freed?
What is logical error?
How are variables declared in c?
an expression contains relational operators, assignment operators, and arithmatic operstors. In the absence of parentheses, they will be evaluated in which of the following order a) assignment, relational, arithematic b) arithematic, relational, assignment c) relational, arithematic, assignment d) assignment, arithematic, relational
What are pointers? Why are they used?
How to find a missed value, if you want to store 100 values in a 99 sized array?
How to implement a packet in C
When the macros gets expanded?
why wipro wase
What are the three constants used in c?
How can you tell whether a program was compiled using c versus c++?
Does c have enums?
Write a program that accept anumber in words
How does normalization of huge pointer works?