Why the following code return error when variable is declared global.
int add(int x, int y) {
return x+y;
}
int ab = add(10, 20);
int main(void) {
printf("%d", ab);
}
But if I call like this:
int add(int x, int y) {
return x+y;
}
int main(void) {
int ab = add(10, 20); // Variable declare inside main
printf("%d", ab);
}
then it executes without an error.