c: refine function notes

This commit is contained in:
Marcello 2025-03-24 22:25:45 +01:00
parent 0f4b290330
commit 46f38332aa
Signed by: m-lamonaca
SSH key fingerprint: SHA256:UYGDdKfMHJzv3yWOf3u8wnbBumU2sLt0cFlZBPFw8AM

View file

@ -402,15 +402,20 @@ It is possible to declare functions **after** the main only if the *prototype* i
To return multiple variables those variables can be passed by reference so that their values is adjourned in the main. To return multiple variables those variables can be passed by reference so that their values is adjourned in the main.
```c ```c
type function_name(type argument1, ...); // function prototype // function prototype (usually in a .h file)
type function_name(type argument1, ...);
type functionName (parameters) { // function implementation (usually in a .c file)
type function_name (parameters) {
return <expression>; return <expression>;
} }
void functionName (parameters) { } // function without a return value
void function_name (parameters) { }
``` ```
> **Note**: annotatic a function with `static` makes it visible only inside the file in which is implemented/declared
### Arguments passed by reference without pointers ### Arguments passed by reference without pointers
Passing arguments by reference causes modifications made inside the function to be propagated to the values outside. Passing arguments by reference causes modifications made inside the function to be propagated to the values outside.
@ -421,9 +426,9 @@ type functionName (type &argument1, ...) {
//code here //code here
return <expression>; return <expression>;
} }
```
`functionName (arguments);` function_name (argument_1, ...);
```
### Arguments passed by reference with pointers ### Arguments passed by reference with pointers
@ -435,9 +440,9 @@ type function_name (type *argument_1, ...) {
instructions; instructions;
return <expression>; return <expression>;
} }
```
`function_name (&argument_1, ...);` function_name (&argument_1, ...);
```
## Arrays ## Arrays