+ 3
What does this mean ?
int x; x = 5; cout << ::x;
5 Respuestas
+ 7
was this part of the code inside of the function or not? Either way, it will cause an error
i guess you know what first 2 lines do, lets move to 3rd one. " :: " is a scope resolution operator, it searches for the thing to the right of it inside the thing to the left of it. You normaly see it when you start working with classes or namespaces. If there is nothing to the left of it, it means that it searches for variable x in the global scope (in case of variables that means it searches for global variable)
but here is what confuses me... If this bit of the code was inside a function, then ::x would cause an error, because x is not global (unless there is one global variable named x which you didnt include in the post). If it wasnt inside a function, then x = 5 and cout would cause an error
+ 2
:: is something like range operator. it reaches outside of the scope to get the x value, so for example if you make new x value in a local scope but there is variable called x outside of that scope you can reach for that variable using ::
+ 1
create a variable named "x" of the type INT.
assign value 5 to variable x.
write x to the console
+ 1
thanks for all..
0
::x ??