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:
- Entry Block:
Entry block allows the control to enter into the control flow graph.
- 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:
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.
Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready.
- Control Flow Software Testing
- Software Engineering | Cash Flow Forecasting
- Software Engineering | Introduction to Software Engineering
- Numeric Control (NC) and Computer Numeric Control (CNC)
- Software Engineering | Requirements Engineering Process
- Software Engineering | Re-engineering
- Software Engineering | Reverse Engineering
- Difference between Software Engineering process and Conventional Engineering Processs
- Difference between Forward Engineering and Reverse Engineering
- Levels in Data Flow Diagrams (DFD)
- Data Flow Testing
- Difference between Structure chart and Flow chart
- Types and Components of Data Flow Diagram (DFD)
- What is DFD(Data Flow Diagram)?
- Functional modeling and Information Flow modeling
- Rules for Data Flow Diagram
- Software Engineering | Halstead’s Software Metrics
- Software Engineering | Classification of Software Requirements
- Software Engineering | Classification of Software
- Software Engineering | Software Project Management Complexities
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.