How many times CppBuzz.com is printed?
int main()
{
int a = 0;
while(a++ < 5-++a)
printf("CppBuzz.com");
return 0;
}
how to solve the expression (5-++a) ?
How many times CppBuzz.com is printed?
int main()
{
int a = 0;
while(a++ < 5-++a)
printf("CppBuzz.com");
return 0;
}
how to solve the expression (5-++a) ?
There is a bigger problem than determining loop counter in your code - undefined behavior.
The line
while(a++ < 5-++a)
tries to increment the same variable a
more than once without a sequence point, it invokes undefined behavior.
That said, if you don't want any conversion specification to happen, don't use printf()
, use puts()
instead.
Code invoked undefined behaviour. Here multiple time variable a
increments.
GCC Compiler generates warning:
prog.c: In function 'main':
prog.c:8:21: warning: operation on 'a' may be undefined [-Wsequence-point]
while(a++ < 5-++a)
^~~