Jump to content

what does int main (void) mean? <c>

adarw

im learing c with cs50 but im confused what does int main (void) mean

 

|:Insert something funny:|

-----------------

*******

#

Link to comment
Share on other sites

Link to post
Share on other sites

that main() returns an int to the shell that is calling it and doesn't take any arguments (void)

Workstation:  14700nonk || Asus Z790 ProArt Creator || MSI Gaming Trio 4090 Shunt || Crucial Pro Overclocking 32GB @ 5600 || Corsair AX1600i@240V || whole-house loop.

LANRig/GuestGamingBox: 9900nonK || Gigabyte Z390 Master || ASUS TUF 3090 650W shunt || Corsair SF600 || CPU+GPU watercooled 280 rad pull only || whole-house loop.

Server Router (Untangle): 13600k @ Stock || ASRock Z690 ITX || All 10Gbe || 2x8GB 3200 || PicoPSU 150W 24pin + AX1200i on CPU|| whole-house loop

Server Compute/Storage: 10850K @ 5.1Ghz || Gigabyte Z490 Ultra || EVGA FTW3 3090 1000W || LSI 9280i-24 port || 4TB Samsung 860 Evo, 5x10TB Seagate Enterprise Raid 6, 4x8TB Seagate Archive Backup ||  whole-house loop.

Laptop: HP Elitebook 840 G8 (Intel 1185G7) + 3080Ti Thunderbolt Dock, Razer Blade Stealth 13" 2017 (Intel 8550U)

Link to comment
Share on other sites

Link to post
Share on other sites

int main(void)

 

is the main function of the program that returns some sort of int to the shell (usually an 0 on success and 1 or -1 on failure) the (void) is a pretty old way of denoting a function takes no arguments. it is typically recommended to stick with the empty () rather than the (void) when making a function that has no arguments. but its all preference.

Link to comment
Share on other sites

Link to post
Share on other sites

21 hours ago, adarw said:

im learing c with cs50 but im confused what does int main (void) mean

 

I get the feeling there's a bit more to your question than you're saying.

Link to comment
Share on other sites

Link to post
Share on other sites

void means the function main has no arguments/parameters

int means the function returns an integer variable, a number.

 

main is the name of the function which is ran by the C runtime once everything is initialized, basically the first code that you wrote which will execute.

It's a "special" function, hardcoded name, but you can probably change it through command line parameters on the c compiler if you really want to.

 

for example you have a function 

 

int calculate_sum(int a, int b) {

 return a+b;

}

 

the function name is calculate_sum, it takes two parameters  a and b which are integer, and returns an integer value.

I think that's right how I wrote it, but I'm not experienced with C, I could be incorrect.

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×