Important Introduction to Programming Short Questions
Chapter: 7
Question 1:
How can a loop be exited early when the correct guess is made in a guessing game?
Answer:
By using a compound condition in the while clause, like while (tryNum <= 5 && c != ‘z’), which exits the loop when either condition becomes false.
Chapter: 7
Question 2:
What are the three components of a for loop?
Answer:
Initialization, continuation/termination condition, and incrementing condition.
Chapter: 7
Question 3:
What does the for loop for (counter = 0; counter < 10; counter = counter +1) do?
Answer:
It prints the numbers 0 through 9, each on a new line.
Chapter: 7
Question 4:
In a for loop, when is the increment statement executed?
Answer:
The increment statement is executed after the loop body has been executed.
Chapter: 7
Question 5:
What happens if the initialization condition in a for loop makes the continuation condition false?
Answer:
The loop body is not executed, and control moves to the statement after the for loop.
Chapter: 7
Question 6:
How can a table of any number be generated using a for loop?
Answer:
By using a variable for the number and a variable for the maximum multiplier, allowing the user to input values.
Chapter: 7
Question 7:
Why should constant values be avoided in a program's logic?
Answer:
Constant values should be avoided because they require changes in multiple places if they need to be updated, leading to more work and possible errors.
Chapter: 7
Question 8:
What is the increment operator in C and how is it used?
Answer:
The increment operator is ++, and it increases the value of its operand by 1.
Chapter: 7
Question 9:
How does the decrement operator -- work in C?
Answer:
The decrement operator decreases the value of its operand by 1.
Chapter: 7
Question 10:
What is the difference between pre-increment and post-increment?
Answer:
Pre-increment increases the value before using it in an expression, while post-increment uses the current value first and then increases it.