Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.
Moderator: Coders of Rage
-
Bludklok
- Chaos Rift Junior
- Posts: 241
- Joined: Tue Apr 14, 2009 1:31 am
- Current Project: EnigmaCore
- Favorite Gaming Platforms: PC, N64, Playstation1, Playstation2
- Programming Language of Choice: C++
- Location: New Jersey
-
Contact:
Post
by Bludklok »
I might be going crazy but in C++ can't you assign a value to a variable in the global scope?
Code: Select all
int a;
a = 20;
int main()
{
return 0;
}
Either my compiler is being retarded and not letting me do this or I'm losing my mind... or I'm tired.
-
qpHalcy0n
- Respected Programmer
- Posts: 387
- Joined: Fri Dec 19, 2008 3:33 pm
- Location: Dallas
-
Contact:
Post
by qpHalcy0n »
int a = 20; // This is value assignment and is valid.
int a;
a = 20; // This is an executable piece of code and is NOT valid in the global scope.
-
Bludklok
- Chaos Rift Junior
- Posts: 241
- Joined: Tue Apr 14, 2009 1:31 am
- Current Project: EnigmaCore
- Favorite Gaming Platforms: PC, N64, Playstation1, Playstation2
- Programming Language of Choice: C++
- Location: New Jersey
-
Contact:
Post
by Bludklok »
qpHalcy0n wrote:int a = 20; // This is value assignment and is valid.
int a;
a = 20; // This is an executable piece of code and is NOT valid in the global scope.
Thought so...
Such a basic rule too. Just been under a lot of stress lately.
-
RyanPridgeon
- Chaos Rift Maniac
- Posts: 447
- Joined: Sun Sep 21, 2008 1:34 pm
- Current Project: "Triangle"
- Favorite Gaming Platforms: PC
- Programming Language of Choice: C/C++
- Location: UK
-
Contact:
Post
by RyanPridgeon »
qpHalcy0n wrote:int a = 20; // This is value assignment and is valid.
Wow, I never realised you could do that in the global scope
Ryan Pridgeon
C,
C++,
C#,
Java,
ActionScript 3,
HaXe,
PHP,
VB.Net,
Pascal
Music | Blog
-
sparda
- Chaos Rift Junior
- Posts: 291
- Joined: Tue Sep 23, 2008 3:54 pm
Post
by sparda »
int a = 20; // This is value assignment and is valid.
assignment != initialization.
That is why you can
initialize:
And not be able to
assign in global scope: