Control Structures - Study Mode

[#101] What will be the output of the following C code? #include <stdio.h>
void main()
{
char *str = ""
do
{
printf("hello")
} while (str)
}
Correct Answer

(D) Hello is printed infinite times

[#102] What will be the output of the following C code? #include <stdio.h>
void main()
{
int i = 0
for (i = 0
i < 5
i++)
if (i < 4)
{
printf("Hello")
break
}
}
Correct Answer

(C) Hello

[#103] What will be the output of the following C code? #include <stdio.h>
int main()
{
short i
for (i = 1
i >= 0
i++)
printf("%d
", i)
}
Correct Answer

(C) Numbers will be displayed until the signed limit of short and program will successfully terminate

[#104] What will be the output of the following C code? #include <stdio.h>
void main()
{
int i = 0
if (i == 0)
{
goto label
}
label: printf("Hello")
}
Correct Answer

(D) Hello

[#105] What will be the output of the following C code? #include <stdio.h>
void main()
{
int i = 0
if (i == 0)
{
printf("Hello")
break
}
}
Correct Answer

(D) Compile time error

Explanation

Solution: The correct answer is D: Compile time error Here's why: In C, the `break` statement is used to exit loops (like `for`, `while`, or `do-while`) or `switch` statements. It's designed to jump out of these control structures. In this code, `break` is placed directly inside an `if` block, but not within any loop or `switch`. The C compiler will detect that `break` is used in an invalid context. Therefore, the program will result in a compile-time error , indicating that the `break` statement is misplaced. The program won't even run. In summary: The `break` statement is only valid inside loops or `switch` statements.