Skip to main content

Branch coverage and unreachable branches

Task 1 

For each example from the section "Statement coverage and unreachable code" (Task 1) of this book, create a Control Flow Graph and identify  branches that are unreachable.

  1. Return Statement Before Print Statement
#include <stdio.h>
int main() 
{
    printf("text_1"); 
    return 0; 
    printf("text_2");
}

Знімок екрана 2025-05-13 133540.pngimage.png

Unreachable:

  • printf("text_2");
    (It comes after the return, so it will never execute.)

2. Infinite Loop Before Statements

#include <stdio.h>
int main() 
{
  int x = 5;
  for (;;) 
  {
    if (x == 5)
    {
      break;
      printf("Hello World"); 
    } 
  }
  return 0;
}

image.pngimage.png

Unreachable:

  • printf("Hello World");
    (It is placed after break, so it will never be executed.)

3. Continue Before Print

#include <stdio.h>
int main() 
{
  for (...int i = 0; i < 10; i++)
  {
    continue;
    printf("Hello World");
  }
  return 0;
}

Знімок екрана 2025-05-13 134423.pngimage.png


Unreachable:

  • printf("Hello World");
    (zawsze pomijane przez continue)

4. False Condition in if Statement

#include <stdio.h>
int main()
{
  double X = 1.55;
  if (X > 5) 
  {
    X++;
  }
  return 0;
}

Знімок екрана 2025-05-13 134436.pngimage.png


Efectively Unreachable at Runtime (dlabut tejstructurally konkretnej wartości X)reachable):

    • X++;
      (ponieważThis line is not executed at runtime for X = 1.55, since the condition X > 5 jestis fałszywe,false. ciałoHowever, it could be executed if the value of ifX niewere jestdifferent, wykonywaneso dlait’s tejnot wartości;marked jednakas kodunreachable samin wthe sobiegraph niesyntax.

      jest
    • strukturalnie nieosiągalny – jest tylko pomijany w tym przypadku)

 Task 2 

For each example from the section "Statement coverage and unreachable code" (Task 2) of this book, create a Control Flow Graph and identify  branches that are unreachable.