I don't get it

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
heyho2
Posts: 3
Joined: September 18th, 2014, 11:11 pm

I don't get it

Post by heyho2 » September 18th, 2014, 11:59 pm

Hey Guys,
i am watching the intermediate at the moment after i paused some month and i came to a Question you will probably all laugh about... (first of all sry for my bad English...).

The thing is if you have this program (Intermediate Lesson 3):

Code: Select all

#include <stdio.h>

int a=1;

void SetA()
{
a = 6;
}

void dispA()
{
printf("%d\n",a);
}

void main()
{
printf("%d\n",a);
SetA();
dispA();
}
This has the Output:
1
6

I expected:
6
6

My Problem is, I don't understand why the function main() is called before SetA()... Is it because SetA() is called in main() or why...

I look forward to read your answers ;)

PutPixel255
Posts: 363
Joined: March 12th, 2013, 6:06 am
Location: "Keep Louisville Weird"

Re: I don't get it

Post by PutPixel255 » September 19th, 2014, 12:27 am

Try doing a desk check. I guess that's an old school term.

cameron
Posts: 794
Joined: June 26th, 2012, 5:38 pm
Location: USA

Re: I don't get it

Post by cameron » September 19th, 2014, 12:35 am

main is defined as the program entry point.
Computer too slow? Consider running a VM on your toaster.

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: I don't get it

Post by chili » September 19th, 2014, 1:17 am

PutPixel255 wrote:desk check
Now that's a name I've not heard in a long time.

Image
Chili

heyho2
Posts: 3
Joined: September 18th, 2014, 11:11 pm

Re: I don't get it

Post by heyho2 » September 19th, 2014, 9:08 am

cameron wrote:main is defined as the program entry point.
does that mean you always have to use main() for the function that starts? That does not sound right does it?

User avatar
LuX
Posts: 1492
Joined: April 22nd, 2012, 12:33 pm
Location: Finland

Re: I don't get it

Post by LuX » September 19th, 2014, 9:33 am

Main it is. Of course you can use a number of custom parameters, but yeah, main is used as the entrypoint.
ʕ •ᴥ•ʔ

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: I don't get it

Post by chili » September 19th, 2014, 10:21 am

The compiler needs to know what code to start the instruction pointer at. Simplest way is just do predefine a symbol. Console apps use main, win32 apps use winmain by default. Might be able to configure that through command line switches or something, but I've never had the need.
Chili

heyho2
Posts: 3
Joined: September 18th, 2014, 11:11 pm

Re: I don't get it

Post by heyho2 » September 19th, 2014, 3:17 pm

Okay thank you very much ;) I will go on with your Tutorial now, btw it is extremely helpful, I have watched some other Videos, tutorials and stuff before but yours is definitely the best, you cover things like Hardware and you explain everything chilled and give the viewer time to think. I hope other people will take you as an model and do some tutorials maybe in German so that I can understand them easier :)

Post Reply