wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

No Strings Attached

Total questions: 20

Worksheet time: 8mins

Name
Class
Date
1.

Which string header should be included in your program to use String class?

a)

string

b)

character

c)

strarr

d)

stringclass

2.

What is the length of the following string?

String str='Good morning!!!';

cout << str.length();

a)

10

b)

15

c)

16

d)

13

3.

How many types of representation are in the string?

a)

1

b)

2

c)

3

d)

4

4.

Which is used to return the number of characters in the string?

a)

length

b)

size

c)

both length and size

d)

none of the above

5.

What is the output of the following code?

String str1 = 'All' + ' ' + 'the' + ' ' + 'best!!';

cout << str1;

a)

Allthebest!!

b)

Allthebest

c)

All the best!!

d)

All the best

6.

Select the output of this snipplet

char str[] = "geeksforgeeks";

cout << 6[str];

a)

e

b)

k

c)

s

d)

o

7.

Which of the following classes is output stream in C++

a)

stdin

b)

ifstream

c)

ofstream

d)

iostream

8.

Which of the following streams is standard output in C++

a)

stdout

b)

print

c)

cerr

d)

cout

9.

Which of the following reads in a string named x with one hundred characters?

a)

cin.getline(x, 100, '\n');

b)

cin.getline(100, x, '\n');

c)

readline(x, 100, '\n');

d)

read(x);

10.

Which of the following functions compares two strings?

a)

compare();

b)

stringcompare();

c)

cmp();

d)

strcmp();

11.

Which of the following adds one string to the end of another?

a)

append();

b)

stringadd();

c)

strcat();

d)

stradd();

12.

All these strncpy ( ), strstr ( ), strok( ), strchr ( ) functions belongs to

a)

<iostream.h>

b)

<stdlib.h>

c)

<string.h>

d)

<array.h>

13.

Which operator is suitable for concatenation function of a string class?

a)

<

b)

<<

c)

++

d)

+

14.

For finding number of characters in string, which function is used?

a)

str_len()

b)

str()

c)

strsize()

d)

strlen()

15.

A string is terminated by a

a)

Null character

b)

Boolean Expression

c)

Semicolon

d)

All of the them

16.

Sequence of contiguous characters in memory, is called as

a)

Functions

b)

Character strings

c)

Arrays

d)

String

17.

What is mean of concatenation?

a)

Separating a string from another string

b)

Adding two functions

c)

Adding two strings

d)

one of them

18.

string s1 = "Welcome to javatpoint";

int len = s1.length();


Give the value of len

a)

19

b)

20

c)

21

d)

22

19.

char str1[] = "user";

char str2[] = "User";

int result = strcmp(str1, str2);


What will be the value of result?

a)

0

b)

1

c)

Null

d)

None

20.

char str1[] = "user";

char str2[] = "user";

int result = strcmp(str1, str2);


What will be the value of result?

a)

0

b)

1

c)

Null

d)

none