Introduction to Programming MCQs with Answers
Practice important Introduction to Programming MCQs with answers and explanations.
Chapter: 34
Q561:
Which of the following statements about delete operator is correct?
A. It deallocates memory without calling the destructor.
B. It is used to deallocate memory for dynamic arrays without brackets.
C. It must be used with empty square brackets for dynamic arrays.
D. It calls the constructor before deallocating memory.
Correct Answer:
C
Chapter: 34
Q562:
What happens if you use delete instead of delete[] for an array of objects?
A. Only the first object in the array is deallocated.
B. All objects in the array are properly deallocated.
C. No memory is deallocated at all.
D. Only the destructor for the first object is called.
Correct Answer:
A
Chapter: 34
Q563:
How does overloading new operator affect memory allocation?
A. It changes the memory block initialization behavior.
B. It changes the memory block allocation strategy.
C. It affects only the destructor calls.
D. It prevents memory leaks by automatically managing memory.
Correct Answer:
B
Chapter: 34
Q564:
In a class with a custom new operator, what happens when a new object is created?
A. The constructor is called before memory allocation.
B. The memory is allocated before calling the constructor.
C. The object is created without initializing memory.
D. The destructor is called before memory allocation.
Correct Answer:
B
Chapter: 34
Q565:
What is the key reason for overloading new and delete operators in embedded systems?
A. To ensure consistent memory allocation and deallocation time.
B. To avoid using the default memory management provided by C++.
C. To prevent memory fragmentation in multi-threaded environments.
D. To simplify memory deallocation.
Correct Answer:
A
Chapter: 35
Q566:
What are the two types of streams in C++?
A. Input and Output Streams
B. File and Network Streams
C. Buffered and Unbuffered Streams
D. Character and Byte Streams
Correct Answer:
A
Chapter: 35
Q567:
Which of the following functions is used in C for formatted output?
A. printf
B. cout
C. cin
D. read
Correct Answer:
A
Chapter: 35
Q568:
What is the purpose of the cin stream in C++?
A. To display output on the screen
B. To perform mathematical operations
C. To take input from the keyboard
D. To read from a file
Correct Answer:
C
Chapter: 35
Q569:
How does the cin stream handle different data types?
A. It ignores data types and stores all as strings
B. It overloads operators to handle various types
C. It converts all data to binary representation
D. It processes input one character at a time
Correct Answer:
B
Chapter: 35
Q570:
What does the cout stream do?
A. It takes input from the user
B. It performs calculations
C. It displays output on the screen
D. It reads from a file
Correct Answer:
C
Chapter: 35
Q571:
What happens if you use cin to read an integer and enter a non-numeric character?
A. The program will execute normally
B. An error will occur
C. The input will be converted to zero
D. The program will terminate
Correct Answer:
B
Chapter: 35
Q572:
Which of the following is true about the << operator used with cout?
A. It inserts data into the output stream
B. It extracts data from the input stream
C. It performs mathematical operations
D. It formats the input data
Correct Answer:
A
Chapter: 35
Q573:
How does the cerr stream differ from cout?
A. cerr is buffered; cout is unbuffered
B. cerr is unbuffered; cout is buffered
C. Both are buffered
D. Both are unbuffered
Correct Answer:
B
Chapter: 35
Q574:
What is the use of endl in C++ streams?
A. It adds a new line to the output and flushes the buffer
B. It adds a new line without flushing the buffer
C. It terminates the program
D. It clears the input buffer
Correct Answer:
A
Chapter: 35
Q575:
What does the getline function do in C++?
A. Reads a single character from the input
B. Reads a complete line up to a delimiter
C. Reads data until the buffer is full
D. Reads and formats data for output
Correct Answer:
B
Chapter: 36
Q576:
Which header file is needed for using manipulators in C++ streams?
A. iostream.h
B. fstream.h
C. iomanip.h
D. iostream.h and fstream.h
Correct Answer:
C
Chapter: 36
Q577:
What function checks if the end of a file has been reached in a stream?
A. cin.fail()
B. cin.bad()
C. cin.eof()
D. cin.clear()
Correct Answer:
C
Chapter: 36
Q578:
What does the function cin.clear() do?
A. It checks the state of the end of file.
B. It clears the error flags and sets the stream to good state.
C. It checks for formatting errors.
D. It sets the fail bit.
Correct Answer:
B
Chapter: 36
Q579:
Which manipulator is used to set the number of decimal places for floating-point numbers?
A. setw()
B. setfill()
C. setprecision()
D. endl()
Correct Answer:
C
Chapter: 36
Q580:
How can you print a number in hexadecimal format using manipulators?
A. cout << hex << i
B. cout << dec << i
C. cout << setw(8) << i
D. cout << setbase(10) << i
Correct Answer:
A