0
Why the result "oo" has putted first and why value of c is showing 5 .?
Problem is in this code ā¬ļø https://code.sololearn.com/cj0CpYYN4Ld8/?ref=app
6 Answers
+ 3
because in your function "sum", the "oo" is already printed before you even return the value
(1) Declared int a = 5;
(2) Calls the function
(3) Condition is false so else statement is executed
(4) Since else is executed "printf("oo")" will also be executed
(5) Returns the value of a (which was not changed and still 5) to the variable "c".
(6) Prints "the number is 5"
Output:
>> oothe number is 5
+ 2
The value is of c is 5 since you are returning that value (return(a) and value of a is 5 therefore c=5).
And of 'oo' since a/2!=0 which is 5/2!=0 but 5/2=2 if condition is returned false therefore else is runned and we got "oo" as output and it is printed first since it is before you return any value.
+ 2
Mr. Unknown
Create void function if you only want to print something and not return values. See this code.
https://code.sololearn.com/ck5N7vlbgzp0/?ref=app
+ 2
ą¦§ą¦Øą§ą¦Æą¦¬ą¦¾ą¦¦
thanks to all community .....
Here I gain what I want ā¬
thanks again
https://code.sololearn.com/cAtu4X3Km0Vb/?ref=app
0
So now what I do if I want only "o" or "oo".... using function
0
Mr. Unknown just put if condition as a==5