Friday, September 20, 2024
Google search engine
HomeGuest BlogsSoftware Engineering | Control Flow Graph (CFG)

Software Engineering | Control Flow Graph (CFG)

A Control Flow Graph (CFG) is the graphical representation of control flow or computation during the execution of programs or applications. Control flow graphs are mostly used in static analysis as well as compiler applications, as they can accurately represent the flow inside of a program unit. The control flow graph was originally developed by Frances E. Allen.

Characteristics of Control Flow Graph:

  • Control flow graph is process oriented.
  • Control flow graph shows all the paths that can be traversed during a program execution.
  • Control flow graph is a directed graph.
  • Edges in CFG portray control flow paths and the nodes in CFG portray basic blocks.

There exist 2 designated blocks in Control Flow Graph:

  1. Entry Block:
    Entry block allows the control to enter into the control flow graph.
  2. Exit Block:
    Control flow leaves through the exit block.

Hence, the control flow graph is comprised of all the building blocks involved in a flow diagram such as the start node, end node and flows between the nodes.

General Control Flow Graphs:
Control Flow Graph is represented differently for all statements and loops. Following images describe it:

1. If-else:

2. while:

3. do-while:

4. for:

Example:

if  A = 10 then
  if B > C
     A = B
  else A = C
  endif
  endif
print A, B, C 

Flowchart of above example will be:

Control Flow Graph of above example will be:

Advantage of CFG:
There are many advantages of a control flow graph. It can easily encapsulate the information per each basic block. It can easily locate inaccessible codes of a program and syntactic structures such as loops are easy to find in a control flow graph.

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

Dominic Rubhabha-Wardslaus
Dominic Rubhabha-Wardslaushttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Recent Comments