+ 4
Global variables
#include <iostream> using namespace std; int x=15; int main() { int x=10; { int x = 5; cout<<::x; } return 0; } is there any way to print x=10 without changing variable names and position of cout?
4 Answers
+ 6
Yes their one way to print 10 write cout<<x; after first cout before return 0 this will print 10
#include <iostream>
using namespace std;
int x=15;
int main()
{
int x=10;
{
int x = 5;
cout<<::x;
}
cout<<x;
return 0;
}
+ 3
sai vamsi
Try to define more variables in main function's primary block, even better, define various types of variables in primary block. Then try again : )
+ 1
#include <iostream>
using namespace std;
int x=15;
int main()
{
int x=10;
{
int x = 5;
cout<<*((&x) + 1);
}
return 0;
}
But this could print x=10 in some compilers. If warnings are avoided.
0
Use a different variable name... Like y...