21. What is the output of the following code snippet in C++? char str[] = "Hello"; cout << str[4]; A. e B. o C. Undefined behavior D. l Answer & Solution Discuss in Board Save for Later Answer & Solution Answer: Option B No explanation is given for this question Let's Discuss on Board
22. In C++, which function is used to read a string with spaces using cin? A. cin.getline(str); B. scanf("%s", str); C. getline(cin, str); D. cin >> str; Answer & Solution Discuss in Board Save for Later Answer & Solution Answer: Option C No explanation is given for this question Let's Discuss on Board
23. What is the correct way to access the fifth character in a string variable named text in C++? A. text(5) B. text[5] C. text.charAt(5) D. text[4] Answer & Solution Discuss in Board Save for Later Answer & Solution Answer: Option D No explanation is given for this question Let's Discuss on Board
24. What is the purpose of the 'toupper()' function in C++? A. Converts a character to uppercase B. Converts a character to lowercase C. Compares two characters D. Returns the length of a string Answer & Solution Discuss in Board Save for Later Answer & Solution Answer: Option A No explanation is given for this question Let's Discuss on Board
25. What is the output of the following code snippet in C++? char str[] = "Hello"; cout << sizeof(str); A. Compilation error B. 4 C. 5 D. 6 Answer & Solution Discuss in Board Save for Later Answer & Solution Answer: Option D No explanation is given for this question Let's Discuss on Board
26. What is the correct way to declare a string object named myString and initialize it with the value "Welcome" in C++? A. myString("Welcome"); B. string myString = "Welcome"; C. char myString[] = "Welcome"; D. None of the above Answer & Solution Discuss in Board Save for Later Answer & Solution Answer: Option B No explanation is given for this question Let's Discuss on Board
27. What does the 'strncpy()' function do in C++? A. Returns the length of a string B. Compares two strings C. Copies a specified number of characters from one string to another D. Concatenates two strings Answer & Solution Discuss in Board Save for Later Answer & Solution Answer: Option C No explanation is given for this question Let's Discuss on Board
28. What is the purpose of the 'strtok()' function in C++? A. Converts a string to lowercase B. Returns the length of a string C. Concatenates two strings D. Tokenizes a string based on a delimiter Answer & Solution Discuss in Board Save for Later Answer & Solution Answer: Option D No explanation is given for this question Let's Discuss on Board
29. Which of the following statements is true about array indices in C++? A. Array indices must be of type 'int' B. Array indices can be negative C. Array indices start from 0 D. Array indices start from 1 Answer & Solution Discuss in Board Save for Later Answer & Solution Answer: Option C No explanation is given for this question Let's Discuss on Board
30. What is the correct way to access the last element of an array named arr in C++? A. arr[end] B. arr[-1] C. arr[size] D. arr[size - 1] Answer & Solution Discuss in Board Save for Later Answer & Solution Answer: Option D No explanation is given for this question Let's Discuss on Board