# Thread: Basic C programming explanations?

1. ## Basic C programming explanations?

Hello I had some questions for a quiz that I got wrong cause I was confused on them. Would anyone please be kind enough to tell me why each code outputs what it does?

1.
Code:
```int a=13, b=5;
if (3 < a < 10)
printf("A");
b = 2*a;
printf("%d", b);
```

shouldn't this just output 26 since 13 isn't less than 10?

2.
Code:

Code:
```int a=8;
if (a = 5) {
printf("A");
}
else
printf("B");
printf("%d", a);
```

shouldn't this just output B due to 8 not being equal to 5?
3.
Code:

Code:
```int a=3, b=8;
if (a > 3)
if (b < 5)
printf("A");
else
printf("B");
printf("C");
```

why doesn't this output both b and c? 2. Code:
```int a=13, b=5;
if (3 < a < 10)
printf("A");
b = 2*a;
printf("%d", b);
```

the expression 3 < a < 10 is equivalent to (3 < a) < 10 and therefore if a is 13, then (3 < 13) < 10 ==> 1 < 10 ==> 1 (true) so the if statement true. The output would be A26

Code:
```int a=8;
if (a = 5) {
printf("A");
}
else
printf("B");
printf("%d", a);
```

Consider:
Code:
`if (a = 5) { // This is assigning 5 to a, and similar to the previous explanation if(5) evaluates to true so the output would be`
Code:
```A5
```

Code:
```int a=3, b=8;
if (a > 3)
if (b < 5)
printf("A");
else
printf("B");
printf("C");
```

fixing indentation:
Code:
```int a=3, b=8;
if (a > 3)
if (b < 5)
printf("A");
else
printf("B");
printf("C");
```

Now it can clearly be seen that only "C" will be printed because the first conditional is false Popular pages Recent additions c programming help 