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
a=10;b= 5;c=3;d=3; if(a printf(%d %d %d %d a,b,c,d) else printf("%d %d %d %d a,b,c,d);
What is the purpose of the following code? Is there any problem with the code? void send(int count, short *to, short *from) { /* count > 0 assumed */ register n = (count + 7) / 8; switch (count % 8) { case 0: do { *to = *from++; case 7: *to = *from++; case 6: *to = *from++; case 5: *to = *from++; case 4: *to = *from++; case 3: *to = *from++; case 2: *to = *from++; case 1: *to = *from++; } while (--n > 0); } }
What does c mean in standard form?
Describe static function with its usage?
Explain c preprocessor?
Explain what’s a signal? Explain what do I use signals for?
what is the syallabus of computer science students in group- 1?
c program to compute AREA under integral
a number whose only prime factors are 2,3,5, and 7 is call humble number,,write a program to find and display the nth element in this sequence.. sample input : 2,3,4,11,12,13, and 100.. sample output : the 2nd humble number is 2,the 3rd humble number is 3,the 4th humble number is ,the 11th humble number is 12, the 12th humble number is 14, the 13th humble number is 15, the 100th humble number is 450.
Should a function contain a return statement if it does not return a value?
What are integer variable, floating-point variable and character variable?
Disadvantages of C language.
Is there anything like an ifdef for typedefs?
Why do we need a structure?
Explain what is the purpose of "extern" keyword in a function declaration?