Introduction to Programming MCQs with Answers
Practice important Introduction to Programming MCQs with answers and explanations.
Chapter: 19
Q321:
What should you expect when you open a binary file containing integers in a text editor like Notepad?
A. The integers will be displayed as plain numbers.
B. The integers will be displayed as binary code.
C. The file will be unreadable or show unexpected characters.
D. The integers will be converted to hexadecimal values.
Correct Answer:
C
Chapter: 19
Q322:
What does the following code snippet do? rFile.seekg(8l, ios::beg);
A. Moves the file pointer 8 bytes forward from the beginning of the file.
B. Moves the file pointer 8 bytes backward from the beginning of the file.
C. Moves the file pointer 8 bytes forward from the current position.
D. Moves the file pointer 8 bytes backward from the current position.
Correct Answer:
A
Chapter: 19
Q323:
What would be the output of this code? rFile.seekg(-16l, ios::end); rFile >>rChar; cout << "the 16th character from the end is " << rChar ;
A. The 16th character from the end of the file will be displayed.
B. The 16th character from the beginning of the file will be displayed.
C. The 8th character from the end of the file will be displayed.
D. The 8th character from the beginning of the file will be displayed.
Correct Answer:
A
Chapter: 19
Q324:
Why is using an if statement considered expensive in terms of computation?
A. It uses a lot of memory.
B. It takes several clock cycles.
C. It slows down the file handling process significantly.
D. It consumes more power.
Correct Answer:
B
Chapter: 19
Q325:
How can you speed up reading from a file at a specific location?
A. By reading the file sequentially from the start.
B. By using the seekg() function to go directly to the location.
C. By reading the file in chunks.
D. By using a higher processing power CPU.
Correct Answer:
B
Chapter: 20
Q326:
What is a structure in C/C++?
A. A collection of variables under a single name
B. A single variable type
C. An array of integers
D. A function pointer
Correct Answer:
A
Chapter: 20
Q327:
How is a structure declared in C/C++?
A. Using the keyword "struct"
B. Using the keyword "class"
C. Using the keyword "typedef"
D. Using the keyword "data"
Correct Answer:
A
Chapter: 20
Q328:
In the structure definition struct student { char name[60]; char address[100]; float GPA; };, what is name?
A. An integer
B. A floating-point number
C. A character array
D. A pointer to a string
Correct Answer:
C
Chapter: 20
Q329:
How can you initialize a structure at the time of declaration?
A. Using curly braces with values
B. Using assignment operators
C. Using the init function
D. Using a constructor
Correct Answer:
A
Chapter: 20
Q330:
What is the correct syntax to define an array of structures?
A. struct student students[100];
B. struct student[] students;
C. student students[100];
D. student[100] students;
Correct Answer:
A
Chapter: 20
Q331:
What is the primary purpose of using a structure in C/C++?
A. To group related data together
B. To store data as a single integer
C. To perform mathematical operations
D. To execute a series of functions
Correct Answer:
A
Chapter: 20
Q332:
How do you access a structure’s member using a pointer to the structure?
A. (*ptr).member
B. ptr->member
C. ptr.member
D. (*ptr->member)
Correct Answer:
B
Chapter: 20
Q333:
Which of the following is true about structures in C/C++?
A. Structures cannot contain other structures
B. Structures can only contain pointers
C. Structures can contain other structures
D. Structures are not extensible
Correct Answer:
C
Chapter: 20
Q334:
Can you directly perform arithmetic operations on structures in C/C++?
A. Yes, using standard arithmetic operators
B. No, structures cannot be directly added
C. Yes, but only with integer structures
D. Yes, with custom operator overloading
Correct Answer:
B
Chapter: 20
Q335:
What is the output of s1.age = 20; if s1 is a variable of type struct student?
A. It updates the age member of s1
B. It creates a new structure s1
C. It initializes s1 to age 20
D. It has no effect on s1
Correct Answer:
A
Chapter: 20
Q336:
What operator is used to access members of a structure through a pointer?
A. *
B. ->
C. .
D. &
Correct Answer:
B
Chapter: 20
Q337:
What does the sizeof operator return when applied to a structure?
A. The number of members in the structure
B. The total number of bytes the structure occupies
C. The size of the largest data member
D. The number of elements in the array
Correct Answer:
B
Chapter: 20
Q338:
What will be the output of sizeof(s1) if s1 is a structure containing two char arrays and two int data types?
A. Depends on the implementation
B. 64 bytes
C. 128 bytes
D. 200 bytes
Correct Answer:
D
Chapter: 20
Q339:
What is the correct way to access the name of the first student in an array of structures named s?
A. s[1].name
B. s[0].name
C. s.name[0]
D. s.name[1]
Correct Answer:
B
Chapter: 20
Q340:
Which operator is used to access members of a structure using a pointer?
A. *
B. ->
C. .
D. &
Correct Answer:
B