Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

strlen(), strcpy(), strcat()

Total questions: 15

Worksheet time: 30mins

Name
Class
Date
1.

What will be the output of the following C code?

  1. #include <stdio.h>

  2. #include <string.h>

  3. int main()

  4. {

  5. char *str = "hello, world";

  6. char *str1 = "hello, world";

  7. if (strcmp(str, str1))

  8. printf("equal");

  9. else

  10. printf("unequal");

  11. }

a)

equal

b)

unequal

c)

Compilation error

d)

Depends on the compiler

2.

What will be the output of the following C code?

  1. #include <stdio.h>

  2. #include <string.h>

  3. int main()

  4. {

  5. char *str = "hello, world";

  6. char str1[15] = "hello wo 9";

  7. strcpy(str, str1);

  8. printf("%s", str1);

  9. }

a)

Compilation error

b)

Segmentation Fault

c)

hello, world

d)

hello, wo 9

3.

What will be the output of the following C code?

  1. #include <stdio.h>

  2. #include <string.h>

  3. int main()

  4. {

  5. char *str = "hello, world";

  6. char str1[9];

  7. strncpy(str1, str, 9);

  8. printf("%s %d", str1, strlen(str1));

  9. }

a)

hello, world 11

b)

hello, wor 9

c)

Undefined behaviour

d)

Compilation error

4.

What will be the output of the following C code?

  1. #include <stdio.h>

  2. #include <string.h>

  3. int main()

  4. {

  5. char *str = "hello, world\n";

  6. printf("%d", strlen(str));

  7.  

  8. }

a)

Compilation error

b)

Undefined behaviour

c)

13

d)

11

5.

What will be the output of the following C code?#include <stdio.h>

  1. #include <string.h>

  2. int main()

  3. {

  4. char str[11] = "hello";

  5. char *str1 = "world";

  6. strcat(str, str1);

  7. printf("%s %d", str, str[10]);

  8. }

a)

helloworld 0

b)

helloworld anyvalue

c)

worldhello 0

d)

Segmentation fault/code crash

6.

Strcat() function adds null character.

a)

Only if there is space

b)

Always

c)

Depends on the standard

d)

Depends on the compiler

7.

What will be the output of the following C code?

  1. #include <stdio.h>

  2. #include <string.h>

  3. int main()

  4. {

  5. char str[10] = "hello";

  6. char *str1 = "world";

  7. strncat(str, str1, 9);

  8. printf("%s", str);

  9. }

a)

helloworld

b)

Undefined behaviour

c)

helloworl

d)

hellowor

8.

Which among the following is Copying function?

a)

memcpy()

b)

strcopy()

c)

memcopy()

d)

strxcpy()

9.

Which function will you choose to join two words?

a)

strcpy()

b)

strcat()

c)

strncon()

d)

memcon()

10.

The ______ function appends not more than n characters.

a)

strcat()

b)

strcon()

c)

strncat()

d)

memcat()

11.

What will strcmp() function do?

a)

compares the first n characters of the object

b)

compares the string

c)

undefined function

d)

copies the string

12.

Which of the following is the variable type defined in header string. h?

a)

sizet

b)

size

c)

size_t

d)

size-t

13.

What is the prototype of strcoll() function?

a)

int strcoll(const char s1,const char s2)

b)

int strcoll(const char *s1)

c)

int strcoll(const s1,const s2)

d)

int strcoll(const *s1)

14.

What is the function of strcoll()?

a)

compares the string, result is dependent on the LC_COLLATE

b)

copies the string, result is dependent on the LC_COLLATE

c)

compares the string, result is not dependent on the LC_COLLATE

d)

copies the string, result is not dependent on the LC_COLLATE

15.

What will be the output of the following C code snippet?

const char pla[] = "string1";

const char pla[] = "string1";

const char src[] = "string2";

printf("Before memmove place= %s, src = %s ", pla, src);

memmove(pla, src, 7);

printf("After memmove place = %s, src = %s\n", pla, src);

a)

Before memmove place= string1, src = string2 After memmove place = string2, src = string2

b)

Before memmove place = string2, src = string2 After memmove place= string1, src = string2

c)

Before memmove place = string2, src = string1 After memmove place= string2, src =string2

d)

Before memmove place= string1, src = string2 After memmove place=string1, src = string1