Computer

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; }

  1. A. Steve
  2. B. jobs
  3. C. St*v* j*bs
  4. D. St*v*
Report Error

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; }

  1. A. 25
  2. B. 26
  3. C. 27
  4. D. 21
Report Error

Which of the following correctly declares an array?

  1. A. int array[10]
  2. B. int array
  3. C. array{10}
  4. D. array array[10]
Report Error

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; }

  1. A. Steve Jobs
  2. B. Apple
  3. C. Jobs Apple Steve
  4. D. Apple Steve
Report Error

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; }

  1. A. apple
  2. B. 12
  3. C. 23
  4. D. Steve jobs founded the
Report Error

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; }

  1. A. Test
  2. B. string
  3. C. Test string
  4. D. Error
Report Error

Which header file is used to manipulate the string?

  1. A. iostream
  2. B. iomanip
  3. C. string
  4. D. container
Report Error

What is the index number of the last element of an array with 9 elements?

  1. A. 9
  2. B. 8
  3. C. 0
  4. D. Programmer-defined
Report Error

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; }

  1. A. ABC
  2. B. ABCD
  3. C. AB
  4. D. AC
Report Error

Which constant member functions does not modify the string?

  1. A. bool empty()
  2. B. assign
  3. C. append
  4. D. delete
Report Error

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; }

  1. A. Steve jo
  2. B. Steve jobs
  3. C. Steve jobs
  4. D. Error
Report Error

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; }

  1. A. I like to code in c
  2. B. I like to code
  3. C. I like to code in c++
  4. D. I like to codeI like to code
Report Error