Statement coverage and unreachable code
TaskIn 1this section we will show unreachable errors using the C language. Unreachable statements are statements that will not be executed during the program execution.
1. Return Statement Before Print Statement
#include <stdio.h>
int main()
{
printf("text_1");
return 0;
printf("text_2");
}
2. Infinite loop before statements
#include <stdio.h>
int main()
{
int x = 5;
for (;;)
{
if (x == 5)
{
break;
printf("Hello World");
}
}
return 0;
}
3. Statements after continue statements
#include <stdio.h>
int main()
{
for (int i = 0; i < 10; i++)
{
continue;
printf("Hello World");
}
return 0;
}
4. False conditions in if statements
#include <stdio.h>
int main()
{
double X = 1.55;
if (X > 5)
{
X++;
}
return 0;
}
Task 2
Show examples of unreachable code based on https://pvs-studio.com/en/blog/terms/0090/
Convert examples to the C language