26 lines
493 B
Markdown
26 lines
493 B
Markdown
|
|
---
|
||
|
|
tags:
|
||
|
|
- C
|
||
|
|
---
|
||
|
|
|
||
|
|
# Entry point to C programs
|
||
|
|
|
||
|
|
```c
|
||
|
|
int main(void)
|
||
|
|
{
|
||
|
|
// Instructions
|
||
|
|
}
|
||
|
|
```
|
||
|
|
|
||
|
|
The braces wrap all code that comprises the program.
|
||
|
|
|
||
|
|
The return type is `int`. It receives no arguments so the arguments are `void`.
|
||
|
|
|
||
|
|
## Why does it return an `int`?
|
||
|
|
|
||
|
|
It returns an `int` because the main function returns a success code: `0` for
|
||
|
|
success and `1` for error.
|
||
|
|
|
||
|
|
As C was divised to create Unix, this fits in with other Unix-like OS behaviour
|
||
|
|
such as bash scripts returning `0`/`1`.
|