Introduction to Programming MCQs with Answers
Practice important Introduction to Programming MCQs with answers and explanations.
Multiple Choice Questions
Q231: What does the statement char myName[] = "Full Name"; do?
- A: Creates a char array and populates it with "Full Name"
- B: Creates a pointer to a char with "Full Name"
- C: Creates a char array but does not initialize it
- D: Creates a pointer to a char but does not initialize it
View Answer
A
Q232: What is the primary difference between char myName[] = "Full Name"; and char *myNamePtr = "Full Name";?
- A: myName is a constant pointer, and myNamePtr can be changed
- B: myName can be changed, and myNamePtr is constant
- C: Both myName and myNamePtr can be changed
- D: Neither myName nor myNamePtr can be changed
View Answer
A
Q233: What does multi + 1 point to in a two-dimensional array char multi[5][10];?
- A: The second element of the first row
- B: The first element of the second row
- C: The second row as a whole
- D: The third row
View Answer
B
Q234: How can you access the element at the second row and third column of multi[5][10] using pointers?
- A: *(*(multi+1)+2)
- B: *(multi+2+1)
- C: **(multi+2)
- D: *(*multi+2)
View Answer
A
Q235: How does the *multi expression behave for a two-dimensional array?
- A: Points to the first element of the first row
- B: Points to the first row
- C: Points to the first element of the first column
- D: Points to the last element of the array
View Answer
B
Q236: In the context of pointers to pointers, what does a double dereference provide?
- A: Access to the value of the variable
- B: Access to the address of the variable
- C: Access to the address of the pointer
- D: Access to the pointer itself
View Answer
A
Q237: What is the main advantage of using an array of pointers for character strings?
- A: It allows variable length strings without wasting space
- B: It simplifies the handling of fixed-size strings
- C: It makes the code more complex
- D: It uses less memory than a fixed-size array
View Answer
A
Q238: What does the argc variable represent in command-line arguments?
- A: The number of command-line arguments
- B: The name of the program
- C: The value of the first argument
- D: The pointer to the argument list
View Answer
A
Q239: How do you convert a command-line argument from a string to an integer?
- A: Use atoi() function
- B: Use itostr() function
- C: Use strtoi() function
- D: Use int() function
View Answer
A
Q240: What is the purpose of the srand() function in random number generation?
- A: To initialize the random number generator with a seed
- B: To generate a random number
- C: To get the current time
- D: To reset the random number generator
View Answer
A