Correct Answer: 8 nodes and 10 edges
To draw the Control Flow Graph, we have to find the number of basic blocks for given code snippet.
A Basic Block is a sequence of instructions where control enters at the beginning of the statement and leave at the end without any halt (except the last statement of the block).
To find number of basic blocks, we have to find the identify of leaders in the code. The rules for finding leaders are as follows:
- First statement in the code is always a leader.
- Statement that is target of an conditional or unconditional goto statement like: if....goto L or goto L is always a leader.
- Statement which immediately follows a conditional or unconditional goto statement is always a leader
Now, that we have found the leader statements, the basic block consists statements starting from one leader and all statement up to another leader, and not including the next leader.
The leaders and basic blocks for given code snippet:
The CFG for given code snippet:
As we can see, CFG has 8 nodes and 10 edges.