wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

C - Strings

Total questions: 20

Worksheet time: 20mins

Name
Class
Date
1.

What is the return value of the following statement if it is placed in C program? strcmp(“ABC”,”ABC”);

a)

33

b)

-1

c)

1

d)

0

2.

Which built in function is used to convert string to lowercase

a)

strlen()

b)

strlwr()

c)

strcmp()

d)

strrev()

3.

Which is not a built in function

a)

string()

b)

strlen()

c)

strcat()

d)

strrev()

4.

String is an array of characters with …….. character as the last element of array.

a)

Null

b)

Empty

c)

0

d)

1

5.

What is the format specifier used to print or read a character in an array in Printf or Scanf function?

a)

%C

b)

%f

c)

%w

d)

%c

6.

Which of the following function is more appropriate for reading in a multi-word string?

a)

scanf()

b)

gets()

c)

printf()

d)

puts()

7.

The library function used to copy a string to another is

a)

strncpy()

b)

strcmp()

c)

strcpy()

d)

strchr()

8.

String is initialized with datatype

a)

float

b)

char

c)

int

d)

double

9.

Strcat() function adds null character

a)

Only if there is space

b)

Always

c)

Depends on the standard

d)

Depends on the compiler

10.

What will be the output of the below program

#include <stdio.h>

#include <string.h>

int main( )

{

   char source[ ] = " fresh2refresh" ;

   char target[ ]= " C tutorial" ;

   strcat ( target, source ) ;

   printf ( "\nTarget string after strcat( ) = %s", target ) ;

}

a)

Target string after strcat( ) =  fresh2refresh

b)

Target string after strcat( ) =  C tutorial

c)

Target string after strcat( ) =

d)

Target string after strcat( ) = C tutorial fresh2refresh

11.

What is the output of this program?

#include <stdio.h>

int main()

{

        char str[] = "hello, world";

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

        }

a)

Compilation error

b)

10

c)

13

d)

12

12.

What is the output of

#include <stdio.h>

int main()

{

    char str[8]="IncludeHelp";

    printf("%s",str);

    return 0;

}

a)

IncludeHelp

b)

IncludeH

c)

Error

d)

No Output

13.

What is the output of this

#include <stdio.h>

#include <string.h>

int main()

{

     char s1[10] = "Hello";

     char s2[10] = "World";

     strncat(s1,s2, 3);

     printf("Concatenation using strncat: %s", s1);

     return 0;

}

a)

Concatenation using strncat: Hel

b)

Concatenation using strncat: HelloWorld

c)

Concatenation using strncat: HelloWor

d)

None of the above

14.

What is the output of

#include <stdio.h>

#include <string.h>

int main()

{

     char s1[30] = "string 1";

     char s2[30] = "string 2: Am using strncpy now";

     strncpy(s1,s2, 12);

     printf("String s1 is: %s", s1);

     return 0;

}

a)

String s1 is: string 2: Am

b)

String s1 is: string 2: A

c)

String s1 is: string  2:

d)

None of the above

15.

What is the output of the below program

#include <stdio.h>

#include <string.h>

int main()

{

char str1[] = "abcd", str2[] = "abcd";

int result;

result = strcmp(str1, str2);

printf("strcmp(str1, str2) = %d\n", result);

return 0;

}

a)

0

b)

1

c)

Invalid

d)

None of the above

16.

What is the output of the below program

#include <stdio.h>

#include <ctype.h>

void strupr(char s[])

{

int i = 0;

while(s[i] != '\0')

{

printf("%c",toupper(s[i]));

i++;

}

printf("\n");

}

int main()

{

strupr("Hello Shivamogga");

return 0;

}

a)

Hello Shivamogga

b)

HELLO Shivamogga

c)

Error

d)

HELLO SHIVAMOGGA

17.

What is the output of the below program

#include <stdio.h>

int main()

{

char str[ ] = "Hello";

int i;

for( i=2; i<4; i++)

{

printf("%c", str[i]);

}

return 0;

}

a)

He

b)

ll

c)

el

d)

lo

18.

What will be the output of the below program

#include <stdio.h>

int main()

{

int a[5]={5,1,15,20,25};

int i,j,m;

i=++a[1];

j=a[1]++;

m=a[i++];

printf("%d,%d,%d",i,j,m);

}

a)

3,2,15

b)

2,3,20

c)

2,1,15

d)

1,2,5

19.

What is the output of the below program

#include <stdio.h>

int main()

{

char str[]="JNNCE", ch='N';

int i, frequency = 0;

for(i = 0; str[i] != '\0'; ++i)

{

if(ch == str[i])

++frequency;

}

printf("Frequency of %c = %d", ch, frequency);

return 0;

}

a)

Frequency of N = 0

b)

Frequency of N = -1

c)

Frequency of N = 2

d)

None of the above

20.

The library function used to calculate the length of the string is

a)

strstr()

b)

strrev()

c)

strlen()

d)

strcat()