I would like to know what is happening in this simple c code:
#include <stdio.h>
int something(int a, int b) {
int c = a * 3 + 4 * b;
}
int main()
{
int res = something(12, 54);
printf("%d\n", res);
return 0;
}
The function does not have the return, however "res" stores the value calculated in something.
Following I show the compilation command, the execution and the output:
$ gcc main.c
$ ./a.out
252
EDITED
I have changed the variables types from int to float, in relation to the @Paul Ogilvie comment, and it seems to return the last int stored:
#include <stdio.h>
float something(int a, int b) {
float res = a * 3 + 4 * b * 1.0;
}
int main() {
float res = something(12, 54);
printf("%d\n", res);
return 0;
}
$ gcc main.c
$ ./a.out
54