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


Please Help Members By Posting Answers For Below Questions

exit () is used to a) exit () terminates the execution of the program itself b) exit () terminates the execution of the loop c) exit () terminates the execution of the block d) none of the above

665


Can you think of a logic behind the game minesweeper.

2010


What is the collection of communication lines and routers called?

614


what is diffrence between linear and binary search in array respect to operators?what kind of operator can be used in both seach methods?

1451


Why do we use int main?

610






Explain what is the general form of a c program?

624


How can I use a preprocessorif expression to ?

601


What are header files why are they important?

580


What are variables c?

620


What are the properties of union in c?

590


What are enumerated types?

655


What is n in c?

575


What does 3 mean in texting?

615


What is a string?

666


What are file streams?

572