0

Is c++ declare different variables of same name?

10th Jan 2017, 2:49 PM
shubham singh
shubham singh - avatar
6 Answers
+ 1
#include <iostream> using namespace std; int a=5; int main() { int a=10; cout<<a<<endl; // outputs 10 cout<<::a; //outputs 5 //thus u have two variable of same name a but their //scope are different one is global anf other is local. // scope resolution operator is used to get global variable's value. return 0; } hope this helps if you have any doubt plz tell me
10th Jan 2017, 3:39 PM
Rishabh Agrawal
Rishabh Agrawal - avatar
0
Yes you can do that but their scope should be different and they should not conflict with each other in same scope.
10th Jan 2017, 3:00 PM
Rishabh Agrawal
Rishabh Agrawal - avatar
0
will you please explain more clear rishabh!!
10th Jan 2017, 3:02 PM
shubham singh
shubham singh - avatar
0
what :: mean?
10th Jan 2017, 4:04 PM
shubham singh
shubham singh - avatar
0
fab man!! thank u so much!!
10th Jan 2017, 4:05 PM
shubham singh
shubham singh - avatar
0
:: is scope resolution operator used to access global value of variable inside any function.
10th Jan 2017, 5:53 PM
Rishabh Agrawal
Rishabh Agrawal - avatar