wats the diference btwen constant pointer and pointer to a
constant.pls give examples.
Answer Posted / surya mukherjee
//POINTER TO CONSTANT vs CONSTANT POINTER
#include<iostream.h>
#include<conio.h>
//POINTER TO CONSTANT
void f1()
{
int i=10,j=20;
const int* pi=&i;
cout<<*pi<<endl;
//*pi = 200; ERROR : CANNOT MODIFY A CONST OBJECT IN f1()
pi=&j; // IT CAN POINT ANOTHER CONSTANT
cout<<*pi<<endl;
}
//CONSTANT POINTER
void f2()
{
int i=100,j;
int* const pi=&i;
cout<<*pi<<endl;
*pi = 200; // IT CAN ASSIGN ANOTHER VALUE AT THIS ADDRESS
cout<<*pi<<endl;
//pi=&j; ERROR : CANNOT MODIFY A CONST OBJECT IN f2()
}
void main()
{
clrscr();
f1();
f2();
getch();
}
| Is This Answer Correct ? | 10 Yes | 1 No |
Post New Answer View All Answers
What is string function c?
What are directives in c?
What is action and transformation in spark?
What are the back slash character constants or escape sequence charactersavailable in c?
Why c is called a middle level language?
Explain what are linked list?
What are type modifiers in c?
the constant value in the case label is followed by a a) semicolon b) colon c) braces d) none of the above
What is c token?
What is function pointer c?
What is the use of define in c?
Explain can the sizeof operator be used to tell the size of an array passed to a function?
cin.ignore(80, _ _);This statement a) ignores all input b) ignores the first 80 characters in the input c) ignores all input till end-of-line d) iteration
What is f'n in math?
How many types of operator or there in c?