Explore BrainMass

Explore BrainMass

    Evaluation of Conditional Expressions in the C language

    This content was COPIED from BrainMass.com - View the original, and get the already-completed solution here!

    What will be printed by the following code?

    int a = 3;

    if (a <= 5)

    if (a < 2)

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

    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?

    © BrainMass Inc. brainmass.com October 9, 2019, 6:52 pm ad1c9bdddf

    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");
    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.