66 982
Assignments Done
99,2%
Successfully Done
In November 2018

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...
Expert's answer
#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

Ask Your question

Submit
Privacy policy Terms and Conditions