CS FundamentalsVery hardTCS Digital · Accenture advanced
Using the convention that each if, else-if, for, while, case, && and || adds 1 to the count of decision points, what is the cyclomatic complexity of this function? int f(int a, int b, int s) { if (a > 0 && b > 0) { for (int i = 0; i < a; i++) { if (i % 2 == 0 || b > i) s++; } } else if (a < 0) s--; while (b > 0 && s < 10) b--; return s; }
- A. 6
- B. 8
- C. 9
- D. 10
Correct answer: C. 9
Decision points: if, &&, for, if, ||, else-if, while, && = 8. Cyclomatic complexity is decision points + 1 = 9. Ignoring the short-circuit operators gives 6; forgetting the +1 gives 8.
Practise more Software Engineering, Git and Cloud Basics questionsSoftware Engineering, Git and Cloud Basics: notes and key points
More Software Engineering, Git and Cloud Basics questions
- For a 32 KLOC project, the Basic COCOMO organic-mode equation Effort = 2.4 x (KLOC)^1.05 person-months gives approximately how much effort?
- Using basic COCOMO in the organic mode (effort = 2.4 × (KLOC)^1.05 person-months), the effort for a 50 KLOC product is closest to:
- A program consists of a main routine and one procedure. Their flow graphs are drawn as two separate connected components with a total of E…
- Three sequential activities lie on the critical path of a project. Their (optimistic, most likely, pessimistic) durations in days are A…
- A server unit has MTTF = 400 hours and MTTR = 100 hours. Two such units fail and are repaired independently, and the service stays up if…
- A product passes through three defect-removal activities that independently catch 60%, 70% and 50% of the defects present when they run…