Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Beginner has a question about the Main( ) function 1

Status
Not open for further replies.

Rmcta

Technical User
Nov 1, 2002
478
US
I read that I can put the main()function wherever I want in my C program and that if I create other functions in my program, main() will always execute first.

What I don't understand then is how the following code works. If the program starts executing the main()function, how can we reference something (integer_test) that has not been read yet?
------------------------------------------------

#include <stdio.h>
int integer_test(int a, int b)
{
int total;
total = a + b;
return total;
}

int main()
sum = integer_test(2,14);
printf("The addition of 2 and 14 is %d\n", sum);
return 0;
}

-----------------------------------------------------
 
Sure it's been read. Just because it starts executing in main doesn't mean it hasn't read the other stuff.

If you make a typo in [tt]integer_test[/tt] and try to compile it, doesn't the compiler notice it and complain? That's where the compiler reads it.
 
I see! thank you very much.
It's clear now. :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top