Explore BrainMass
Share

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

    © BrainMass Inc. brainmass.com October 9, 2019, 6:52 pm ad1c9bdddf
    https://brainmass.com/computer-science/c/evaluation-conditional-expressions-language-100334

    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