Why this code throws error | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why this code throws error

About void main and loop #include<stdio.h> void main() { int i; for(i=1; i<=10; i++) printf("%d",i); }

22nd Jul 2022, 4:12 AM
Laukesh singh
Laukesh singh - avatar
8 Answers
+ 1
Felix Alcor yeah thanks you I rechecked it's fine Thank you for your help 😊
22nd Jul 2022, 4:44 AM
Laukesh singh
Laukesh singh - avatar
0
it's int main() and not void main()
22nd Jul 2022, 4:17 AM
Felix Alcor
Felix Alcor - avatar
0
Felix Alcor what if I want to use void what chances i need to do
22nd Jul 2022, 4:19 AM
Laukesh singh
Laukesh singh - avatar
0
It is only a warning, not an error, to remind you that main should not be void. Console programs should return an int so shell scripts may report whether the execution was successful. It is conventional that if a program returns 0, then the run was successful, and non-zero means it was unsuccessful.
22nd Jul 2022, 4:23 AM
Brian
Brian - avatar
0
Laukesh singh You Code still works and Like Brian said it's just a reminder. When you don't Like the warning just use int main().
22nd Jul 2022, 4:27 AM
Felix Alcor
Felix Alcor - avatar
0
Felix Alcor yeah but I ran the code and I'm not getting expected output (if it just a warning than atleast code should run right?) And what if I want to use VOID then what chances code required
22nd Jul 2022, 4:31 AM
Laukesh singh
Laukesh singh - avatar
0
Laukesh singh When I Run the Code I get the Output "12345678910" and that should be also the right Output by that Code and then behind that's the warning. What's your expected output?
22nd Jul 2022, 4:41 AM
Felix Alcor
Felix Alcor - avatar
0
Change main() function.
23rd Jul 2022, 6:07 AM
PARTH CHAUHAN
PARTH CHAUHAN - avatar