0
What is the use of y in this c language program
#include<stdio.h> int square (int number) { int y; y=number*number; } main() { int x=5; int result; result=square(x); printf("\n%d squared=%d",x,result); return 0; } In this program we are not using y after main function but in its absence it is showing error how the declaration y=number*number working here
2 ответов
+ 2
the function need a return value, which is missed and if you try to return y, it will return the value since y is a local variable which will have been erased from the stack after the loop has completed its function, so you can just do
return number*number; and skip the use of y