CS FundamentalsVery hardProduct-company placement · GATE CS
How many definition-use (def-use) pairs does variable x have in this fragment (a p-use in a condition counts as a use)?
How many definition-use (def-use) pairs does variable x have in this fragment (a p-use in a condition counts as a use)?
x = int(input()) # 1
y = 0 # 2
if x > 10: # 3
y = x * 2 # 4
else:
x = x + 1 # 6
print(x, y) # 7- A. 3
- B. 4
- C. 6
- D. 5
Correct answer: D. 5
The definition at 1 reaches uses at 3, 4, 6 and also 7 (along the path through line 4, where x is not redefined); the definition at 6 reaches 7. That makes 5 pairs. Missing (1, 7) gives 4.
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 the function below, the tests (age = 30, member = True) and (age = 10, member = False) already give 100% statement and branch…
- McCabe's V(G) = E - N + 2 for one function comes from the cyclomatic number of a strongly connected graph, E - N + P. Where does the '+2'…
- A loan is approved if (salary ≥ ₹50,000 AND credit history is good) OR a guarantor is provided. Using a limited-entry decision table with…
- An ATM state machine: inserting a card leads to '1st try'. A correct PIN in any try state leads to 'Access'; a wrong PIN moves 1st → 2nd →…
- A price field accepts amounts from ₹0.01 to ₹999.99, with exactly two decimal places. Which pair of values are the invalid boundary values…
- For the function below, what are its cyclomatic complexity and the number of times a[j] > a[j + 1] is evaluated for the input [2, 1, 3, 4…