Console Closing Down

Pages: 1... 567
It displayed "Hello world" after you pressed Enter.

int c is a global variable, hence, as Bazzy said, it is executed before main(). Since it is initialized with a function call, that function call also gets executed before main. :-O Yep, you read that right. (It is generally not a very good idea to do that kind of thing though.)

Try it again, but make sure you run it directly from the command prompt.

Click Start --> Programs --> Accessories --> Command Prompt. (Or Start --> Run... and enter "cmd" in the dialogue.)

Change to the directory where the program's exe is found. For example, on my computer, I compiled the example as D:\prog\cc\foo\a.exe. So my command prompt session looked like this:

Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\Michael> d:

D:\> cd prog\cc\foo

D:\prog\cc\foo> a.exe

At this point, the program is running and waiting for me to press a key. I pressed 'j'. (Any key would have done.) After pressing the key the program finishes by executing main() and quitting.

Hello world

Hope this helps.
Topic closed to new replies.
Pages: 1... 567