0
why 2 and 3 are behaving so
1.This prints "it is 10"- int main() {int x,y; x=5; y=5; int result=x+y; printf("it is %d ",result); } int fact(){ int x,y; x=5; y=5; int result=x+y; return result;} 2.This prints nothing- int main() { printf(it is %d",fact()); } int fact(){int x,y; x=5; y=5; int result=x+y; printf(result); } 3.This prints "10 it is 0" - int fact(){int x, y; x=5; y=5; int result= x+y; printf("%d ",result); } int main() { printf("it is %d",fact()); return 0; }
2 Antworten
+ 3
function which has int or float return type should return something.
Your 2nd and 3rd function doesn't have return value.
in 2nd case function should be declare first and printf should have %d to print value.
0
2. This code has a syntax error and will not compile. The printf statement in main is missing a closing quotation mark.
3. This code defines a fact function that adds two variables x and y (both set to 5) and prints the result. In main, it calls fact and tries to print the return value, but the function fact doesn't return anything. Therefore, it prints "0" which is the default return value for functions when no explicit return statement is present.