Full Transcript

**Possible questions about flow of control in programming** 1\. What is a flow of control in programming? **Answer**: It refers to the order in which individual statements, instructions, or function calls are executed or evaluated. 2\. What are the three basic types of control flow structures? *...

**Possible questions about flow of control in programming** 1\. What is a flow of control in programming? **Answer**: It refers to the order in which individual statements, instructions, or function calls are executed or evaluated. 2\. What are the three basic types of control flow structures? **Answer**: Sequential, Selection (conditional), and Iteration (looping). 3\. What is the primary purpose of conditional statements? **Answer**: To execute a specific block of code only if a certain condition is true. 4\. Which statement is used in most programming languages to make decisions based on conditions? **Answer**: The if statement. 5\. How does the else statement work in programming? **Answer**: It provides an alternative block of code to be executed if the if condition evaluates to false. 6\. What is the difference between if-else and if-else if-else structures? **Answer**: if-else handles only two possible outcomes, while if-else if-else handles multiple conditions. 7\. What is the purpose of a switch/case statement? **Answer**: It allows a variable to be tested against a list of values, and execute corresponding code when a match is found. 8\. In a switch statement, what is the role of the break statement? **Answer**: It exits the switch block after a case has been executed, preventing fall-through. 9\. What is a looping control structure? **Answer**: A structure that repeats a block of code as long as a certain condition is true. 10\. Name three common types of loops in programming. **Answer**: for, while, and do-while loops. 11\. What is the difference between a while loop and a do-while loop? **Answer**: In a while loop, the condition is checked before executing the loop body, while in a do-while loop, the condition is checked after the loop body has executed at least once. 12\. In a for loop, what are the three main components inside the parentheses? **Answer**: Initialization, condition, and iteration (update). 13\. How does a continue statement affect the flow of control in a loop? **Answer**: It skips the current iteration of the loop and moves to the next iteration. 14\. What does a break statement do in a loop? **Answer**: It immediately exits the loop, skipping any remaining iterations. 15\. What is recursion in programming? **Answer**: It is a process in which a function calls itself to solve a problem. 16\. When should recursion be used instead of loops? **Answer**: When a problem can be divided into smaller sub-problems that are identical to the original, or when using algorithms like tree traversal or factorial computation. 17\. What can cause infinite loops in programming? **Answer**: A condition that is always true or never being updated properly to become false. 18\. What is a nested loop? **Answer**: A loop inside another loop, where the inner loop is executed completely for each iteration of the outer loop. 19\. What is the complexity concern with nested loops? **Answer**: They can lead to high time complexity, typically multiplying the execution time of the loops (e.g., O(n\^2) for two nested loops). 20\. What is the difference between entry-controlled and exit-controlled loops? **Answer**: Entry-controlled loops (like for and while) check the condition before the loop body executes, while exit-controlled loops (like do-while) check the condition after the loop body executes. 21\. What is the purpose of a control flow graph (CFG)? **Answer**: It visually represents the flow of control in a program, showing paths based on decisions, loops, and sequences of code 22\. What happens if the condition in an if statement is false? **Answer**: The block of code inside the if statement is skipped. 23\. How do you terminate a loop early if a certain condition is met? **Answer**: By using the break statement. 24\. What is a ternary operator and how does it control flow? **Answer**: It is a concise form of an if-else statement, often written as condition ? expression1 : expression2, where expression1 is executed if the condition is true, and expression2 is executed if it is false. 25\. How does exception handling affect the flow of control? **Answer**: It alters the normal flow of control by transferring it to exception-handling blocks (e.g., try-catch), bypassing the usual execution path when an error or exception occurs.

Use Quizgecko on...
Browser
Browser