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 does the c in ctime mean?
What is void main () in c?
What is the most efficient way to count the number of bits which are set in an integer?
Is return a keyword in c?
Explain the use of function toupper() with and example code?
Why pointers are used?
How can you increase the size of a statically allocated array?
Write a program to produce the following output: 1 2 3 4 5 6 7 8 9 10
Explain bitwise shift operators?
what is event driven software and what is procedural driven software?
What is the purpose of type declarations?
Explain how does flowchart help in writing a program?
How can I write functions that take a variable number of arguments?
Hai sir, I had planned to write the NIC scientific engineer exam , plz post the sample question......
Which is more efficient, a switch statement or an if else chain?