Share
Explore BrainMass

Evaluation of Conditional Expressions in the C language

What will be printed by the following code?

int a = 3;

if (a <= 5)

if (a < 2)

printf("a is less than 2n");
else
printf("a is greater than 5n");
printf("done");

Why does this occur?

What if the initial value assigned to a is 13, not 3? What happens with this code and why does this occur? What does this tell you about setting up conditional expressions in the C language?

Solution Preview

This happens because when properly formatted the code is like following.
int a = 3; //or a =13

if (a <= 5){
if (a < 2){
printf("a is less than 2n");
else
printf("a is greater ...

Solution Summary

Shows how to interpret conditional expressions, such as if .. else so that the code works properly with the help of braces.

$2.19