+ 1

Can you tell me the reason behind output? It shows sololearn

#include<stdio.h> int main() { do{ printf("sololearn"); }while(5,3,0); }

12th May 2021, 5:01 PM
Hridoy Banik
4 Answers
+ 2
Jerry Hobby yes its not valid condition but if we will write any positive number or non zero numbers then its treat as a true like if i write like this if(5) here 5 is non zero so it will be true and statement will be execute. In case of a=(1,2,3) if we will print values of a it will print 3 right so same here do while loop execute atleast once so sololearn will be print once
12th May 2021, 6:44 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 1
That doesn't even compile. It doesn't show "sololearn" because it doesn't even run. In case you edit the question, here is what I'm looking at now: #includr<stdio.h> int main() { printf("sololearn"); }while(5,3,0); } Here are the messages: ./Playground/file0.c:1:2: error: invalid preprocessing directive #includr; did you mean #include? 1 | #includr<stdio.h> | ^~~~~~~ | include ./Playground/file0.c: In function 'main': ./Playground/file0.c:4:1: warning: implicit declaration of function 'printf' [-Wimplicit-function-declaration] 4 | printf("sololearn"); | ^~~~~~ ./Playground/file0.c:4:1: warning: incompatible implicit declaration of built-in function 'printf' ./Playground/file0.c:1:1: note: include '<stdio.h>' or provide a declaration of 'printf' +++ |+#include <stdio.h> 1 | #includr<stdio.h> ./Playground/file0.c: At top level: ./Playground/file0.c:5:2: error: expected identifier or '(' before 'while' 5 | }while(5,3,0); | ^~~~~ ./Playground/file0.c:6:1: error: expected identifier or '(' before '}' token 6 | } | ^ Why doesn't it compile? Your while-loop condition is messed up. It needs to be an expression that can be evaluated to something representing true or false and "5,3,0" doesn't work. It is "include" not "includr". {} brackets are not balanced. You have more closing } than opening {. A minor warning would be shown because your main function returns int but then you have no return statement.
12th May 2021, 5:07 PM
Josh Greig
Josh Greig - avatar
0
Josh Greig edited!
12th May 2021, 5:08 PM
Hridoy Banik
0
What is the point of (5,3,0). That’s not a valid condition, logically.
12th May 2021, 5:46 PM
Jerry Hobby
Jerry Hobby - avatar