Why is it always false? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why is it always false?

#include <stdio.h> int main() { char *str; int i = 0; int flows = 0; while (*(str + i) != '\0') { if ((int)(*(str + 1)) == 32) { if (*(str + i - 1) == *(str + i + 1)) flows = 1; else flows = 0; } i++; } if (flows) printf("true"); else printf("false"); return 0; }

3rd Nov 2022, 3:25 PM
Dulgan Danjuma
Dulgan Danjuma - avatar
1 Answer
+ 1
Dulgan Danjuma it happens more or less by random chance, depending on whatever happens to be in memory when and where you run this program. Notice the warning you get by running this on Sololearn. The pointer variable str is never initialized. You have to presume that str holds an unpredictable memory address that holds unpredictable values.
4th Nov 2022, 4:04 AM
Brian
Brian - avatar