0

C language ; operator working princible

I realized that C compliers doesnt give errors when only put ; repeatly. I mean ; is used to execute a task. But when no task is given what does it execute ? I am leaving an example. #include <stdio.h> int main() { ; ; ; return 0; }

17th Aug 2020, 8:59 AM
Emre İRİŞ
Emre İRİŞ - avatar
5 Réponses
0
its like its executing nothing over and over again, then returns 0
17th Aug 2020, 9:02 AM
Slick
Slick - avatar
0
Slick we have NOP() to execute nothing. NOP stands for no operation
17th Aug 2020, 9:04 AM
Emre İRİŞ
Emre İRİŞ - avatar
0
Right, but there is literally nothing for gcc to compile. So technically it would have no errors. Thats the only thing i can think. like in a for loop AFTER you have assigned an int variable. ... int i=0 for(;i<5;i++) ... The assignment is skipped but it still runs fine because there are technically no errors.
17th Aug 2020, 9:09 AM
Slick
Slick - avatar
0
Slick hımm kinda make sense. Still one thing is not clear, it is not valid in while loop. If no input is given to while loop it throws an error. You can try. while() { printf("hello world\n"); }
17th Aug 2020, 9:15 AM
Emre İRİŞ
Emre İRİŞ - avatar
0
True, but i think thats just because of the nature of a while loop. They can work on conditinal alone. That works if you throw a 1 in there: while(1)... while(1)... //is the same as: int i=1; for(;;)...
17th Aug 2020, 9:34 AM
Slick
Slick - avatar