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

20th Jul 2019, 4:13 PM
S.S.A.V Panchajanya
2 Réponses
+ 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
20th Jul 2019, 5:15 PM
✳AsterisK✳
✳AsterisK✳ - avatar