Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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


Please Help Members By Posting Answers For Below Questions

Why doesnt this code work?

1057


How to get string length of given string in c?

1065


List some basic data types in c?

1025


Function calling procedures? and their differences? Why should one go for Call by Reference?

1082


Is flag a keyword in c?

1149


What's the total generic pointer type?

1052


Describe newline escape sequence with a sample program?

1116


Why c is called a mid level programming language?

1068


What are preprocessor directives in c?

1094


What the different types of arrays in c?

1059


What are examples of structures?

1104


what is recursion in C

1060


What is function and its example?

1209


What is array in C

1152


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?

1498