-7

How can the code work like this? Which if-else statements are linked with each other? So why is the output like that "$$$$$"?

#include <stdio.h>
int main() {
    int x = 11;
    int y = 9;

    if(x<10)
    if(y>10)
    puts("*****");
    else
    puts("#####");
    puts("$$$$$");
    return 0;
}
Atakan
  • 1
  • 1
  • 4
    ­­­­­-­­­­­1 Why not just use the curly brackets and avoid the confusion? –  Dec 07 '19 at 20:41

1 Answers1

1

Save time. Use an auto formatter.

Hopefully then "why is the output like that "$$$$$"?" is self apparent.

#include <stdio.h>
int main() {
  int x = 11;
  int y = 9;

  if (x < 10)
    if (y > 10)
      puts("*****");
    else
      puts("#####");
  puts("$$$$$");
  return 0;
}
chux - Reinstate Monica
  • 143,097
  • 13
  • 135
  • 256