Important Introduction to Programming Short Questions
Chapter: 38
Question 1:
How does the star manipulator function?
Answer:
It inserts an asterisk (*) into the output stream.
Chapter: 38
Question 2:
What does the sound manipulator do?
Answer:
The sound manipulator makes a system beep by inserting the alert character (\a) into the output stream.
Chapter: 38
Question 3:
Why use static keyword for variables?
Answer:
The static keyword maintains the value of a variable between function calls and avoids the pitfalls of global variables.
Chapter: 38
Question 4:
How does a static variable behave compared to a local variable?
Answer:
A static variable retains its value between function calls, while a local variable does not.
Chapter: 38
Question 5:
What is the initialization requirement for a static variable?
Answer:
A static variable must be initialized once during its declaration. For example: static int i = 0;.
Chapter: 38
Question 6:
Can you use a static variable inside the main function?
Answer:
Yes, but it's not common since main is executed only once. Static variables are more useful within other functions that are called multiple times.
Chapter: 38
Question 7:
How does the newLine manipulator function in the example?
Answer:
It inserts a newline character (endl) into the output stream.
Chapter: 38
Question 8:
What is the purpose of the spaceBetween manipulator?
Answer:
It sets the output stream's width to 4 using setw(4) to format spacing between elements.
Chapter: 38
Question 9:
What is the difference between static and automatic variables?
Answer:
Static variables are initialized once and persist for the lifetime of the program, while automatic variables are reinitialized each time a function is called and destroyed when the function exits.
Chapter: 38
Question 10:
What happens if you remove the static keyword from a variable in a function?
Answer:
The variable will be treated as an automatic variable, meaning it will be reinitialized every time the function is called.