29.1k views
4 votes
2) Describe the output produced by this poorly indented program segment:

int number = 4;
double alpha = -1.0;
if (number > 0)
if (alpha > 0)
printf("Here I am! \\" );
else
printf("No, I’m here! \\");
printf(“No, actually, I’m here! \\");

User Arnaldo
by
7.3k points

1 Answer

4 votes

The output produced by this program segment is:

"Here I am!"

"No, actually, I'm here!"

The first "if" statement checks if the value of "number" is greater than 0, which it is, so the second "if" statement is executed.

The second "if" statement checks if the value of "alpha" is greater than 0, which it is not, so the "else" statement is executed.

Then, the final printf statement is executed regardless of the outcome of the if-else statement.

It should be noted that the poor indentation of the code can be confusing and make it difficult to understand the control flow of the program.

User Manukn
by
7.8k points