Arrays And Strings In C Plus Plus — Part 1 MCQs with Explanations
Practice high-yield Programming & Software Development MCQs on Arrays And Strings In C Plus Plus — Part 1 with worked academic solutions for FPSC, PPSC, NTS, NITB, PTS.
Questions
40
Difficulty Level
Exam-Level
Target Exams
FPSC, PPSC, NTS...
Estimated Time
48 mins
Exam-Level FPSC PPSC NTS NITB PTS
Verified for Commission Syllabus • Oct 14, 2026
40
Verified Practice Questions
Interactive test mode with detailed academic worked solutions
Live Progress|0/40 answered
✓0 correct
✗0 wrong
0% score
🎉 Set complete! All 40 questions answered.
Question 1 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the correct way to declare a one-dimensional array in C++?
Correct Answer: Option D — int arr[size]
Detailed Academic Explanation:
int arr[size] is the correct answer to “What is the correct way to declare a one-dimensional array in C++”. This question is standard in competitive examination syllabi for Arrays And Strings In C Plus Plus.
💡Key Conceptual Anchor:Arrays And Strings In C Plus Plus
Question 2 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How do you access the third element of an array named 'arr' in C++?
Correct Answer: Option C — arr[2]
Detailed Academic Explanation:
arr[2] is the correct answer to “How do you access the third element of an array named 'arr' in C++”. This question is standard in competitive examination syllabi for Arrays And Strings In C Plus Plus.
💡Key Conceptual Anchor:Arrays And Strings In C Plus Plus
Question 3 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the size of the following array declaration in C++: char str[10];?
Correct Answer: Option B — 10
Detailed Academic Explanation:
10 is the correct answer to “What is the size of the following array declaration in C++: char str[10];”. This question is standard in competitive examination syllabi for Arrays And Strings In C Plus Plus.
💡Key Conceptual Anchor:Arrays And Strings In C Plus Plus
Question 4 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the 'strlen()' function in C++?
Correct Answer: Option C — Returns the length of a null-terminated string
Detailed Academic Explanation:
Returns the length of a null-terminated string is the correct answer to “What is the purpose of the 'strlen()' function in C++”. This question is standard in competitive examination syllabi for Arrays And Strings In C Plus Plus.
💡Key Conceptual Anchor:Arrays And Strings In C Plus Plus
Question 5 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How do you initialize all elements of an integer array named 'arr' to zero in C++?
Correct Answer: Option D — for (int i = 0; i < size; ++i) { arr[i] = 0; }
Detailed Academic Explanation:
for (int i = 0; i < size; ++i) { arr[i] = 0; } is the correct answer to “How do you initialize all elements of an integer array named 'arr' to zero in C++”. This question is standard in competitive examination syllabi for Arrays And Strings In C Plus Plus.
💡Key Conceptual Anchor:Arrays And Strings In C Plus Plus
Question 6 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the correct syntax for declaring a two-dimensional array in C++?
Correct Answer: Option A — int arr[rowSize][colSize]
Detailed Academic Explanation:
int arr[rowSize][colSize] is the correct answer to “What is the correct syntax for declaring a two-dimensional array in C++”. This question is standard in competitive examination syllabi for Arrays And Strings In C Plus Plus.
💡Key Conceptual Anchor:Arrays And Strings In C Plus Plus
Question 7 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following statements is true about C-style strings in C++?
Correct Answer: Option D — They are represented as arrays of characters terminated by a null character
Detailed Academic Explanation:
They are represented as arrays of characters terminated by a null character is the correct answer to “Which of the following statements is true about C-style strings in C++”. This question is standard in competitive examination syllabi for Arrays And Strings In C Plus Plus.
💡Key Conceptual Anchor:Arrays And Strings In C Plus Plus
Question 8 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the output of the following code: char str[] = "Hello"; cout << str[5]; in C++?
Correct Answer: Option C — Undefined behavior
Detailed Academic Explanation:
Undefined behavior is the correct answer to “What is the output of the following code: char str[] = "Hello"; cout << str[5]; in C++”. This question is standard in competitive examination syllabi for Arrays And Strings In C Plus Plus.
💡Key Conceptual Anchor:Arrays And Strings In C Plus Plus
Question 9 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How do you determine the length of a C-style string in C++?
Correct Answer: Option B — Using the 'strlen()' function
Detailed Academic Explanation:
Using the 'strlen()' function is the correct answer to “How do you determine the length of a C-style string in C++”. This question is standard in competitive examination syllabi for Arrays And Strings In C Plus Plus.
💡Key Conceptual Anchor:Arrays And Strings In C Plus Plus
Question 10 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the correct way to pass an array as an argument to a function in C++?
Correct Answer: Option C — Using a pointer to the array
Detailed Academic Explanation:
Using a pointer to the array is the correct answer to “What is the correct way to pass an array as an argument to a function in C++”. This question is standard in competitive examination syllabi for Arrays And Strings In C Plus Plus.
💡Key Conceptual Anchor:Arrays And Strings In C Plus Plus
Question 11 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What does the 'strcpy()' function do in C++?
Correct Answer: Option D — Copies one string to another
Detailed Academic Explanation:
Copies one string to another is the correct answer to “What does the 'strcpy()' function do in C++”. This question is standard in competitive examination syllabi for Arrays And Strings In C Plus Plus.
💡Key Conceptual Anchor:Arrays And Strings In C Plus Plus
Question 12 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the output of the following code: char str[] = "Hello"; cout << sizeof(str); in C++?
Correct Answer: Option A — 6
Detailed Academic Explanation:
6 is the correct answer to “What is the output of the following code: char str[] = "Hello"; cout << sizeof(str); in C++”. This question is standard in competitive examination syllabi for Arrays And Strings In C Plus Plus.
💡Key Conceptual Anchor:Arrays And Strings In C Plus Plus
Question 13 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the correct way to initialize a string object named 'str' in C++?
Correct Answer: Option D — string str = "Hello"
Detailed Academic Explanation:
string str = "Hello" is the correct answer to “What is the correct way to initialize a string object named 'str' in C++”. This question is standard in competitive examination syllabi for Arrays And Strings In C Plus Plus.
💡Key Conceptual Anchor:Arrays And Strings In C Plus Plus
Question 14 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the 'strcat()' function in C++?
Correct Answer: Option C — Concatenates two strings
Detailed Academic Explanation:
Concatenates two strings is the correct answer to “What is the purpose of the 'strcat()' function in C++”. This question is standard in competitive examination syllabi for Arrays And Strings In C Plus Plus.
💡Key Conceptual Anchor:Arrays And Strings In C Plus Plus
Question 15 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the output of the following code: char str[] = "Hello"; cout << str; in C++?
Correct Answer: Option B — Hello
Detailed Academic Explanation:
Hello is the correct answer to “What is the output of the following code: char str[] = "Hello"; cout << str; in C++”. This question is standard in competitive examination syllabi for Arrays And Strings In C Plus Plus.
💡Key Conceptual Anchor:Arrays And Strings In C Plus Plus
Question 16 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following correctly initializes a two-dimensional array named matrix in C++ with dimensions 3x3?
Correct Answer: Option C — int matrix[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}
Detailed Academic Explanation:
int matrix[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}} is the correct answer to “Which of the following correctly initializes a two-dimensional array named matrix in C++ with dimensions 3x3”. This question is standard in competitive examination syllabi for Arrays And Strings In C Plus Plus.
💡Key Conceptual Anchor:Arrays And Strings In C Plus Plus
Question 17 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the output of the following code snippet in C++? int arr[] = {1, 2, 3, 4, 5}; cout << arr[5];
Correct Answer: Option D — Undefined behavior
Detailed Academic Explanation:
Undefined behavior is the correct answer to “What is the output of the following code snippet in C++? int arr[] = {1, 2, 3, 4, 5}; cout << arr[5];”. This question is standard in competitive examination syllabi for Arrays And Strings In C Plus Plus.
💡Key Conceptual Anchor:Arrays And Strings In C Plus Plus
Question 18 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following correctly defines a string variable named name initialized with the value "John" in C++?
Correct Answer: Option A — string name = "John"
Detailed Academic Explanation:
string name = "John" is the correct answer to “Which of the following correctly defines a string variable named name initialized with the value "John" in C++”. This question is standard in competitive examination syllabi for Arrays And Strings In C Plus Plus.
💡Key Conceptual Anchor:Arrays And Strings In C Plus Plus
Question 19 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the 'strcmp()' function in C++?
Correct Answer: Option D — Compares two C-style strings
Detailed Academic Explanation:
Compares two C-style strings is the correct answer to “What is the purpose of the 'strcmp()' function in C++”. This question is standard in competitive examination syllabi for Arrays And Strings In C Plus Plus.
💡Key Conceptual Anchor:Arrays And Strings In C Plus Plus
Question 20 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following correctly declares an array of 10 integers in C++ and initializes all elements to zero?
Correct Answer: Option C — int arr[10] = {0}
Detailed Academic Explanation:
int arr[10] = {0} is the correct answer to “Which of the following correctly declares an array of 10 integers in C++ and initializes all elements to zero”. This question is standard in competitive examination syllabi for Arrays And Strings In C Plus Plus.
💡Key Conceptual Anchor:Arrays And Strings In C Plus Plus
Question 21 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the output of the following code snippet in C++? char str[] = "Hello"; cout << str[4];
Correct Answer: Option B — o
Detailed Academic Explanation:
o is the correct answer to “What is the output of the following code snippet in C++? char str[] = "Hello"; cout << str[4];”. This question is standard in competitive examination syllabi for Arrays And Strings In C Plus Plus.
💡Key Conceptual Anchor:Arrays And Strings In C Plus Plus
Question 22 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In C++, which function is used to read a string with spaces using cin?
Correct Answer: Option C — getline(cin, str)
Detailed Academic Explanation:
getline(cin, str) is the correct answer to “In C++, which function is used to read a string with spaces using cin”. This question is standard in competitive examination syllabi for Arrays And Strings In C Plus Plus.
💡Key Conceptual Anchor:Arrays And Strings In C Plus Plus
Question 23 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the correct way to access the fifth character in a string variable named text in C++?
Correct Answer: Option D — text[4]
Detailed Academic Explanation:
text[4] is the correct answer to “What is the correct way to access the fifth character in a string variable named text in C++”. This question is standard in competitive examination syllabi for Arrays And Strings In C Plus Plus.
💡Key Conceptual Anchor:Arrays And Strings In C Plus Plus
Question 24 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the 'toupper()' function in C++?
Correct Answer: Option A — Converts a character to uppercase
Detailed Academic Explanation:
Converts a character to uppercase is the correct answer to “What is the purpose of the 'toupper()' function in C++”. This question is standard in competitive examination syllabi for Arrays And Strings In C Plus Plus.
💡Key Conceptual Anchor:Arrays And Strings In C Plus Plus
Question 25 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the output of the following code snippet in C++? char str[] = "Hello"; cout << sizeof(str);
Correct Answer: Option D — 6
Detailed Academic Explanation:
6 is the correct answer to “What is the output of the following code snippet in C++? char str[] = "Hello"; cout << sizeof(str);”. This question is standard in competitive examination syllabi for Arrays And Strings In C Plus Plus.
💡Key Conceptual Anchor:Arrays And Strings In C Plus Plus
Question 26 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the correct way to declare a string object named myString and initialize it with the value "Welcome" in C++?
Correct Answer: Option B — string myString = "Welcome"
Detailed Academic Explanation:
string myString = "Welcome" is the correct answer to “What is the correct way to declare a string object named myString and initialize it with the value "Welcome" in C++”. This question is standard in competitive examination syllabi for Arrays And Strings In C Plus Plus.
💡Key Conceptual Anchor:Arrays And Strings In C Plus Plus
Question 27 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What does the 'strncpy()' function do in C++?
Correct Answer: Option C — Copies a specified number of characters from one string to another
Detailed Academic Explanation:
Copies a specified number of characters from one string to another is the correct answer to “What does the 'strncpy()' function do in C++”. This question is standard in competitive examination syllabi for Arrays And Strings In C Plus Plus.
💡Key Conceptual Anchor:Arrays And Strings In C Plus Plus
Question 28 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the 'strtok()' function in C++?
Correct Answer: Option D — Tokenizes a string based on a delimiter
Detailed Academic Explanation:
Tokenizes a string based on a delimiter is the correct answer to “What is the purpose of the 'strtok()' function in C++”. This question is standard in competitive examination syllabi for Arrays And Strings In C Plus Plus.
💡Key Conceptual Anchor:Arrays And Strings In C Plus Plus
Question 29 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following statements is true about array indices in C++?
Correct Answer: Option C — Array indices start from 0
Detailed Academic Explanation:
Array indices start from 0 is the correct answer to “Which of the following statements is true about array indices in C++”. This question is standard in competitive examination syllabi for Arrays And Strings In C Plus Plus.
💡Key Conceptual Anchor:Arrays And Strings In C Plus Plus
Question 30 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the correct way to access the last element of an array named arr in C++?
Correct Answer: Option D — arr[size - 1]
Detailed Academic Explanation:
arr[size - 1] is the correct answer to “What is the correct way to access the last element of an array named arr in C++”. This question is standard in competitive examination syllabi for Arrays And Strings In C Plus Plus.
💡Key Conceptual Anchor:Arrays And Strings In C Plus Plus
Question 31 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How do you declare a multidimensional array with 3 rows and 4 columns in C++?
Correct Answer: Option D — int arr[3][4]
Detailed Academic Explanation:
int arr[3][4] is the correct answer to “How do you declare a multidimensional array with 3 rows and 4 columns in C++”. This question is standard in competitive examination syllabi for Arrays And Strings In C Plus Plus.
💡Key Conceptual Anchor:Arrays And Strings In C Plus Plus
Question 32 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the output of the following code: char str[10]; cout << sizeof(str); in C++?
Correct Answer: Option C — 10
Detailed Academic Explanation:
10 is the correct answer to “What is the output of the following code: char str[10]; cout << sizeof(str); in C++”. This question is standard in competitive examination syllabi for Arrays And Strings In C Plus Plus.
💡Key Conceptual Anchor:Arrays And Strings In C Plus Plus
Question 33 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which function is used to find the first occurrence of a specified substring within a string in C++?
Correct Answer: Option B — strstr()
Detailed Academic Explanation:
strstr() is the correct answer to “Which function is used to find the first occurrence of a specified substring within a string in C++”. This question is standard in competitive examination syllabi for Arrays And Strings In C Plus Plus.
💡Key Conceptual Anchor:Arrays And Strings In C Plus Plus
Question 34 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the output of the following code: char str[] = "Hello"; cout << str[0] << str[4]; in C++?
Correct Answer: Option C — Ho
Detailed Academic Explanation:
Ho is the correct answer to “What is the output of the following code: char str[] = "Hello"; cout << str[0] << str[4]; in C++”. This question is standard in competitive examination syllabi for Arrays And Strings In C Plus Plus.
💡Key Conceptual Anchor:Arrays And Strings In C Plus Plus
Question 35 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In C++, what is the purpose of the 'cin.getline()' function?
Correct Answer: Option D — Reads a line of text from standard input
Detailed Academic Explanation:
Reads a line of text from standard input is the correct answer to “In C++, what is the purpose of the 'cin.getline()' function”. This question is standard in competitive examination syllabi for Arrays And Strings In C Plus Plus.
💡Key Conceptual Anchor:Arrays And Strings In C Plus Plus
Question 36 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How do you declare a string object named 'text' in C++?
Correct Answer: Option A — string text
Detailed Academic Explanation:
string text is the correct answer to “How do you declare a string object named 'text' in C++”. This question is standard in competitive examination syllabi for Arrays And Strings In C Plus Plus.
💡Key Conceptual Anchor:Arrays And Strings In C Plus Plus
Question 37 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the correct syntax for declaring an array of 5 integers in C++?
Correct Answer: Option D — int arr[5]
Detailed Academic Explanation:
int arr[5] is the correct answer to “What is the correct syntax for declaring an array of 5 integers in C++”. This question is standard in competitive examination syllabi for Arrays And Strings In C Plus Plus.
💡Key Conceptual Anchor:Arrays And Strings In C Plus Plus
Question 38 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the 'cin.ignore()' function in C++?
Correct Answer: Option C — Clears the input buffer
Detailed Academic Explanation:
Clears the input buffer is the correct answer to “What is the purpose of the 'cin.ignore()' function in C++”. This question is standard in competitive examination syllabi for Arrays And Strings In C Plus Plus.
💡Key Conceptual Anchor:Arrays And Strings In C Plus Plus
Question 39 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the output of the following code: char str[] = "Hello"; cout << strlen(str); in C++?
Correct Answer: Option B — 5
Detailed Academic Explanation:
5 is the correct answer to “What is the output of the following code: char str[] = "Hello"; cout << strlen(str); in C++”. This question is standard in competitive examination syllabi for Arrays And Strings In C Plus Plus.
💡Key Conceptual Anchor:Arrays And Strings In C Plus Plus
Question 40 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the correct syntax to declare a string literal in C++?
Correct Answer: Option A — const char* str = "Hello"
Detailed Academic Explanation:
const char* str = "Hello" is the correct answer to “What is the correct syntax to declare a string literal in C++”. This question is standard in competitive examination syllabi for Arrays And Strings In C Plus Plus.
💡Key Conceptual Anchor:Arrays And Strings In C Plus Plus
✓Link copied to clipboard
Continue Your Practice
Advance Html — Part 1
Master the next curriculum module with 40 exam-standard MCQs.
💡Examiner's Advisory for Programming & Software Development
In competitive commission exams (FPSC, PPSC, KPPSC, SPSC, CSS, PMS), questions are frequently phrased with distractor options designed to catch rote learners. Whenever you answer an MCQ, read the Detailed Academic Explanation and Conceptual Anchor to understand why the remaining options are incorrect.