0
Is c++ declare different variables of same name?
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
0
Yes you can do that but their scope should be different and they should not conflict with each other in same scope.
0
will you please explain more clear rishabh!!
0
what :: mean?
0
fab man!! thank u so much!!
0
:: is scope resolution operator used to access global value of variable inside any function.