Introduction to Programming MCQs with Answers
Practice important Introduction to Programming MCQs with answers and explanations.
Chapter: 20
Q341:
In the sample program, how is the maximum GPA determined?
A. By comparing GPA values during input
B. By finding the highest GPA in the array after input
C. By using the GPA value of the last student
D. By calculating the average GPA
Correct Answer:
B
Chapter: 20
Q342:
What will the output be if the average GPA is 3.5 in the sample program?
A. The average Grade of the class is A
B. The average Grade of the class is B
C. The average Grade of the class is C
D. The average Grade of the class is F
Correct Answer:
B
Chapter: 20
Q343:
In the file handling sample program, what function is used to read data from a file and return a structure?
A. writeData()
B. openFile()
C. getData()
D. writeData()
Correct Answer:
C
Chapter: 20
Q344:
How does the union intOrChar handle memory?
A. Each member has its own memory space
B. All members share the same memory space
C. It uses twice the memory of the largest member
D. It uses half the memory of the largest member
Correct Answer:
B
Chapter: 20
Q345:
What is the size of the union intOrDouble?
A. Equal to the size of int
B. Equal to the size of double
C. Equal to the combined size of int and double
D. Depends on the system architecture
Correct Answer:
B
Chapter: 20
Q346:
In the union example, what happens when you assign 'a' to the integer member and then access the character array?
A. The character array shows 'a' and the integer value shows the ASCII code of 'a'
B. The character array shows 'a' in all positions
C. The integer value shows the ASCII code of 'a'
D. The character array shows 'a' and 'b'
Correct Answer:
A
Chapter: 20
Q347:
How is the file opened in the sample program for input and output?
A. Using ifstream and ofstream
B. Using fstream only
C. Using ifstream only
D. Using ofstream only
Correct Answer:
A
Chapter: 20
Q348:
In the union example, what will be the output of the integer value after multiple shifts and additions?
A. It will show the concatenated result of all characters
B. It will show only the last character added
C. It will show the sum of all characters' ASCII codes
D. It will show the ASCII code of the first character
Correct Answer:
A
Chapter: 20
Q349:
What function is used to write a student structure to a file?
A. getData()
B. openFile()
C. writeData()
D. readData()
Correct Answer:
C
Chapter: 20
Q350:
What is the purpose of the sizeof operator when used with structures?
A. To determine the number of members
B. To find the size of each data member
C. To find the total memory occupied by the structure
D. To count the number of elements in the structure
Correct Answer:
C
Chapter: 20
Q351:
How many bytes does the union intOrChar occupy if int is 4 bytes and char is 1 byte?
A. 1 byte
B. 4 bytes
C. 5 bytes
D. 8 bytes
Correct Answer:
B
Chapter: 20
Q352:
Which statement about unions is true?
A. All members share the same memory location
B. Each member has its own memory location
C. The size of the union is the sum of the sizes of its members
D. Unions are used to create arrays of different types
Correct Answer:
A
Chapter: 21
Q353:
What is the basic unit of memory in computers?
A. Byte
B. Bit
C. Nibble
D. Word
Correct Answer:
B
Chapter: 21
Q354:
How many bits form a byte?
A. 4
B. 8
C. 16
D. 32
Correct Answer:
B
Chapter: 21
Q355:
Which operator returns 1 if both input bits are 1?
A. Bitwise OR
B. Bitwise AND
C. Bitwise XOR
D. Bitwise NOT
Correct Answer:
B
Chapter: 21
Q356:
What is the result of applying the Bitwise AND operator on binary 1100 and 1000?
A. 100
B. 1100
C. 1000
Correct Answer:
C
Chapter: 21
Q357:
Which operator is used to check if a specific bit in a number is set?
A. Bitwise OR
B. Bitwise XOR
C. Bitwise AND
D. Bitwise NOT
Correct Answer:
C
Chapter: 21
Q358:
What does the Bitwise OR operator do?
A. Returns 1 if both bits are 1
B. Returns 1 if at least one bit is 1
C. Returns 1 if only one of the bits is 1
D. Inverts all bits
Correct Answer:
B
Chapter: 21
Q359:
What is the result of 8 ^ 1 where 8 is 1000 and 1 is 0001 in binary?
A. 1001
B. 1
C. 101
D. 1100
Correct Answer:
A
Chapter: 21
Q360:
If a = 5 and b = 3, what will be the result of a ^ b followed by c ^ b where c = a ^ b?
A. a
B. b
C. c
Correct Answer:
A