Page 1 of 1

I don't get it

Posted: September 18th, 2014, 11:59 pm
by heyho2
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 ;)

Re: I don't get it

Posted: September 19th, 2014, 12:27 am
by PutPixel255
Try doing a desk check. I guess that's an old school term.

Re: I don't get it

Posted: September 19th, 2014, 12:35 am
by cameron
main is defined as the program entry point.

Re: I don't get it

Posted: September 19th, 2014, 1:17 am
by chili
PutPixel255 wrote:desk check
Now that's a name I've not heard in a long time.

Image

Re: I don't get it

Posted: September 19th, 2014, 9:08 am
by heyho2
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?

Re: I don't get it

Posted: September 19th, 2014, 9:33 am
by LuX
Main it is. Of course you can use a number of custom parameters, but yeah, main is used as the entrypoint.

Re: I don't get it

Posted: September 19th, 2014, 10:21 am
by chili
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.

Re: I don't get it

Posted: September 19th, 2014, 3:17 pm
by heyho2
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 :)