Answer to Question #46780 in C++ for pramod

Question #46780
#include<stdio.h>
int a=10;
main()
{
int a=20;
printf ("%d",a);
}

question : output of the code is a=20 but i want also print the old value of a (10), with out using pointers ? or suggest me other possible methods too...
1
Expert's answer
2014-09-25T09:42:56-0400
#include<stdio.h>
#include<stdlib.h>
//value a
int a=10;
//main method
void main(){
int a=20;
//print 20
printf ("%d\n",a);
//print 10
printf ("%d\n",::a);
//delay
system("pause");
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

Assignment Expert
25.09.14, 16:46

Thank you! We've corrected answer and category.

pramod
24.09.14, 21:32

no u should do this with SRO(scope resolution operator) then u can also access also the old value of variable(a)

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS