+ 1
Exit() exits us from loop or exits us from program????
2 odpowiedzi
0
Try yourself in playground:
(1) for (int i=0; i<2; i++);
printf("hello\n");
Is "hello" printed ? Yes!
(2) for (int i=0; i<2; i++) exit(0);
printf("hello\n");
Is "hello" printed ? No!
This means that exit() not only exits from the loop, like "break", but also from the program
0
$|<|>_&£ understand two keyword first exit and break
Exit terminate the program while break is as a name suggest break the loop if u want exit a program in such conditions
File *fptr=fopen("some.txt","r")
If(fptr==NULL)
exit(1)//it terminate the program
2.break
For (i=0;i<9;i++)
{ If(i==3)
break;
Printf("%d",i);
}
Printf("\n%d",i);
Output is
12
3
I hope u understand