The following program runs perfectly fine without showing compilation error. I am unable to understand why as 'c' is a local variable of 'function_addition'. So, shouldn't it throw an error?
#include<stdio.h>
int function_addition(int a, int b)
{
int c;
c = 10;
return c;
}
int main()
{ //function_addition(13, 15);
printf("%d", function_addition(13,15) );
}
Also, another similar program involving strings(see below) throws an error when we try to print it in a similar way.
#include<stdio.h>
char *getstring(){
char str[]="GateOverflow";
return str;
}
int main()
{
printf("%s", getstring());
}// Gives error
Please explain me this ambiguity as to why the first one prints the value of c correctly whereas the second program shows an error.