Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Strings

Total questions: 6

Worksheet time: 3mins

Name
Class
Date
1.

What is returned from strlen("test\n");

a)

4

b)

5

c)

6

d)

7

2.

Given char buffer[81], which statement correctly reads a single line into buffer?

a)

gets(buffer);

b)

fgets(buffer, 81, stdin);

c)

scanf("%s", buffer);

d)

scanf("%80s", buffer);

3.

Given char buffer[81], which statement correctly reads a single word into buffer?

a)

gets(buffer);

b)

fgets(buffer, 81, stdin);

c)

scanf("%s", buffer);

d)

scanf("%80s", buffer);

4.

Which expression is true, if pointer test points to string with content "test"?

a)

test == "test"

b)

strcmp(test, "test") == 0

c)

strcmp(test, "test")

d)

strstr(test, "test") == 0

5.

We have char str[81] = "test". How do we concatenate it with "string"?

a)

strcat(str, "string");

b)

strcpy(str, "string");

c)

str += "string";

d)

str = "teststring";

6.

Let

char *test = "teststring";

char *ptr = strstr(test, "str");

What is the value of ptr - test?

a)

Undefined.

b)

0

c)

4

d)

5