What is the output? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

What is the output?

#include <stdio.h> int main(){ int n; for(n=3;n!=0;n--) printf("n=%d",n--); return 0; }

30th Jun 2017, 3:48 AM
Morarji Surati
Morarji Surati - avatar
8 Answers
+ 18
3 2 1
30th Jun 2017, 3:59 AM
Frost
Frost - avatar
+ 1
@ACE ,there is no need of int because the function didn't return anything
30th Jun 2017, 4:06 AM
Morarji Surati
Morarji Surati - avatar
+ 1
@ACE even though your out put is wrong
30th Jun 2017, 4:11 AM
Morarji Surati
Morarji Surati - avatar
+ 1
in the printf n is decrementing ,so the value didn't hit 0 ,so the loops runs infinite times
30th Jun 2017, 4:19 AM
Morarji Surati
Morarji Surati - avatar
+ 1
yes write @moraji surati
30th Jun 2017, 4:21 AM
Rohan Vijayvergiya
Rohan Vijayvergiya - avatar
0
the a above code is in c language that's why it don't need an int to return a value, in c basically main function work with void,so no error occur. and the result is n=3n=2n=1
30th Jun 2017, 4:16 AM
Rohan Vijayvergiya
Rohan Vijayvergiya - avatar
0
output is n=3 n=1 n=-1 because n-- is written twice.
30th Jun 2017, 9:24 AM
Sandeep Sood
Sandeep Sood - avatar
30th Jun 2017, 9:42 AM
Rohan Vijayvergiya
Rohan Vijayvergiya - avatar