Test: Strings - 2


10 Questions MCQ Test Learn to Program with C++: Beginner to Expert | Test: Strings - 2


Description
This mock test of Test: Strings - 2 for Back-End Programming helps you for every Back-End Programming entrance exam. This contains 10 Multiple Choice Questions for Back-End Programming Test: Strings - 2 (mcq) to study with solutions a complete question bank. The solved questions answers in this Test: Strings - 2 quiz give you a good mix of easy questions and tough questions. Back-End Programming students definitely take this Test: Strings - 2 exercise for a better result in the exam. You can find other Test: Strings - 2 extra questions, long questions & short questions for Back-End Programming on EduRev as well by searching above.
QUESTION: 1

Which of the following function is used to find the first occurrence of a given string in another string?

Solution:

The function strstr() Finds the first occurrence of a substring in another string
Declaration: char *strstr(const char *s1, const char *s2);
Return Value:
On success, strstr returns a pointer to the element in s1 where s2 begins (points to s2 in s1).
On error (if s2 does not occur in s1), strstr returns null.

QUESTION: 2

Choose the operator which cannot be overloaded.

Solution:

Scope resolution (::) is not permitted to be overloaded.

QUESTION: 3

If the two strings are identical, then strcmp() function returns

Solution:

Declaration: strcmp(const char *s1, const char*s2);
The strcmp return an int value that is
if s1 < s2 returns a value < 0 if s1 == s2 returns 0 if s1 > s2 returns a value > 0

QUESTION: 4

In the following program f() is overloaded.

Solution:

No, as both the functions arguments is same and compiler ignores return type to consider overloading though different in return type.

QUESTION: 5

What will be the output of the program ?

Solution:

gets() gets collects a string of characters terminated by a new line from the standard input stream stdin.

The gets(str1) read the input string from user and store in variable str1.

The gets(str2) read the input string from user and store in variable str2.

The code i = strcmp(str1, str2); The strcmp not only returns -1, 0 and +1, but also other negative or positive values. So the value of i is “unpredictable integer value”.

printf(“%d\n”, i); It prints the value of variable i.

QUESTION: 6

What is the full form of RTTI.

Solution:
QUESTION: 7

What will be the output of the program ?

Solution:

The function printf() returns the number of charecters printed on the console.

char a[] = “\0″; The variable a is declared as an array of characters and it initialized with “\0″. It denotes that the string is empty.

if(printf(“%s”, a)) The printf() statement does not print anything, so it returns ‘0’(zero). Hence the if condition is failed.

In the else part it prints “not empty string”.

QUESTION: 8

What is the output of the following program?

Solution:

No output, as we are comparing both base addresses and are not same.

QUESTION: 9

What will be the output of the program ?

Solution:

A string is a collection of characters terminated by ‘\0′.

char str[] = “Code\0Quiz\0″; The variable str is declared as an array of characters and initialized with value “Code”

printf(“%s\n”, str); It prints the value of the str.

The output of the program is “Code”.

QUESTION: 10

Following is the invalid inclusion of a file to the current program. Identify it

Solution:

option (a) & (b) are valid. There is no such syntax or provision as in option (c).

Similar Content

Related tests