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
Why doesnt this code work?
How to get string length of given string in c?
List some basic data types in c?
Function calling procedures? and their differences? Why should one go for Call by Reference?
Is flag a keyword in c?
What's the total generic pointer type?
Describe newline escape sequence with a sample program?
Why c is called a mid level programming language?
What are preprocessor directives in c?
What the different types of arrays in c?
What are examples of structures?
what is recursion in C
What is function and its example?
What is array in C
Given an array of 1s and 0s arrange the 1s together and 0s together in a single scan of the array. Optimize the boundary conditions?