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 extern storage class in c?
what is recursion in C
regarding pointers concept
How many levels of indirection in pointers can you have in a single declaration?
Explain how do you list files in a directory?
Explain about C function prototype?
What are the differences between Structures and Arrays?
How can I get the current date or time of day in a c program?
What is the usage of the pointer in c?
How can I write functions that take a variable number of arguments?
When was c language developed?
How can I discover how many arguments a function was actually called with?
Why do we need functions in c?
How can I determine whether a machines byte order is big-endian or little-endian?
What is a null string in c?