Arrays And Strings In C Plus Plus MCQs
Practice Arrays And Strings In C Plus Plus MCQs for competitive exams.
Arrays And Strings In C Plus Plus MCQs
Practice questions from this topic.
What will be the output of the following C++ code? #include #include using namespace std; int main () { string str ("Steve jobs"); unsigned long int found = str.find_first_of("aeiou"); while (found != string :: npos) { str[found] = '*'; found = str.find_first_of("aeiou", found + 1); } cout << str << 'n'; return 0; }
Correct Answer: C
What will be the output of the following C++ code? #include #include using namespace std; int main () { int array[] = {0, 2, 4, 6, 7, 5, 3}; int n, result = 0; for (n = 0; n < 8; n++) { result += array[n]; } cout << result; return 0; }
Correct Answer: C
Which of the following correctly declares an array?
Correct Answer: A
What will be the output of the following C++ code? #include #include using namespace std; int main () { string name ("Jobs"); string family ("Steve"); name += " Apple "; name += family; name += 'n'; cout << name; return 0; }
Correct Answer: C
What will be the output of the following C++ code? #include #include using namespace std; int main () { string str ("Steve jobs founded the apple"); string str2 ("apple"); unsigned found = str.find(str2); if (found != string :: npos) cout << found << 'n'; return 0; }
Correct Answer: C
What will be the output of the following C++ code? #include #include using namespace std; int main () { string str ("Test string"); for ( string :: iterator it = str.begin(); it != 5; ++it) cout << *it; return 0; }
Correct Answer: D
Which header file is used to manipulate the string?
Correct Answer: C
What is the index number of the last element of an array with 9 elements?
Correct Answer: B
What will be the output of the following C++ code? #include #include using namespace std; int main() { char str[5] = "ABC"; cout << str[3]; cout << str; return 0; }
Correct Answer: A
Which constant member functions does not modify the string?
Correct Answer: A
What will be the output of the following C++ code? #include #include #include using namespace std; int main () { string str ("Steve jobs"); char * cstr = new char [str.length() + 1]; strcpy (cstr, str.c_str()); char * p = strtok (cstr," "); while (p != 0) { cout << p << 'n'; p = strtok(NULL," "); } delete[] cstr; return 0; }
Correct Answer: C
What will be the output of the following C++ code? #include #include using namespace std; int main () { string str ("I like to code in C"); unsigned sz = str.size(); str.resize (sz + 2, '+'); str.resize (14); cout << str << 'n'; return 0; }
Correct Answer: B
