I came across this piece of code in C:
#include
main( )
{
int i = 5;
workover(i);
printf(\"%d\",i);
}
workover(i)
int i;
{
i = i*i;
retu
When I compile your code as $ gcc common.c -o common.exe -Wall
(Trying it over Cygwin Terminal as I don't have my linux system with me right now)
I get following warnings:
common.c:3:1: warning: return type defaults to ‘int’ [-Wreturn-type]
main( )
^
common.c: In function ‘main’:
common.c:6:2: warning: implicit declaration of function ‘workover’ [-Wimplicit-f unction-declaration]
workover(i);
^
common.c: At top level:
common.c:9:1: warning: return type defaults to ‘int’ [-Wreturn-type]
workover(i)
^
common.c: In function ‘main’:
common.c:8:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
return type defaults to ‘int’ which means that if you don't specify a return type, compiler will implicitly declare it as int.implicit declaration of function ‘workover’ since the compiler doesn't know what workover is.You should do it this way:
#include
int workover(int);
int i;
int main(void)
{
int i = 5;
workover(i);
printf("%d",i); //prints 5
return 0;
}
int workover(int i)
{
i = i*i; //i will have local scope, so after this execution i will be 25;
return(i); //returns 25
}