wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Strings C

Total questions: 82

Worksheet time: 1hrs 4mins

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()

21.

str1="6/4";

printf("str1");

a)

6/4

b)

str1

c)

None

22.

What is right way to Initialize array?

a)

int num[6] = { 2, 4, 12, 5, 45, 5 };

b)

int n{} = { 2, 4, 12, 5, 45, 5 };

c)

int n{6} = { 2, 4, 12 };

d)

int n(6) = { 2, 4, 12, 5, 45, 5 };

23.

An array elements are always stored in ________ memory locations.

a)

sequential

b)

Random

c)

Sequential and Random

d)

None of the above

24.

what will be printed after Execution of the following program

void main()

{

int a[5]={11,13,56,20,5};

printf("%d",a[2]);

}

a)

garbage value

b)

13

c)

56

d)

20

25.

if two strings are identical then function strcmp() returns

a)

0

b)

-1

c)

true

d)

none of these

26.

what will be the output of the program?

#include <stdio.h>

#include<string .h>

void main()

{

char str1[20]="Hello",str2="world";

strcat(str1,str2);

puts(str1);

return 0;

}

a)

Hello

b)

world

c)

Helloworld

d)

none of the above

27.

8.Which of the following correctly accesses the seventh element stored in arr, an array with 100 elements?

a)

arr[6]

b)

arr[7]

c)

arr{6}

d)

arr{7}

28.

What is a String in C Language.?

a)

String is a new Data Type in C

b)

String is an array of Characters with null character as the last element of array.

c)

String is an array of Characters with null character as the first element of array

d)

String is an array of Integers with 0 as the last element of array

29.

An array Index starts with.?

a)

-1

b)

0

c)

1

d)

2

30.

What is the minimum and maximum Indexes of this below array.?

int main()

{

int ary[9];

return 0;

}

a)

-1, 8

b)

0, 8

c)

1,9

d)

None of the above

31.

What is the output of this program

#include <stdio.h>

int main()

{ int a[2][] = { {1,1,1},{2,2,2}};

printf("%d", a[1][1]);

}

a)

1

b)

Error

c)

2

d)

0

32.

Given the code, what is in values[2][1] ?

a)

7.9

b)

9.2

c)

7.3

d)

0.5

33.

Each piece of data in an array is BEST described as a what?

a)

Integer and string

b)

Item

c)

Element

d)

Elephant

34.

Which BEST describes an array?

a)

A data structure - Stores a collection of values under one name

b)

A data collection - Stores a structure of values under one name

c)

A list - Stores a list of numbers

d)

A list - Stores a list of strings

35.

How would you get the value "6" out of the following array?

a)

a [0][3]

b)

a [1][3]

c)

c) a[0][2]

d)

d) a[2][0]

e)

e) a[3][1]

36.

What will be the output of the C program?


#include<stdio.h>

int main()

{

int 1_one = 25;

printf("%d",1_one);

return 0;

}

a)

2

b)

25

c)

1

d)

Compilation Error

37.

The fastest data access is provided using __________

a)

Caches

b)

DRAM’s

c)

SRAM’s

d)

Registers

38.

What is the output of the following printf


printf("%d",34+24/12%3*5/2-4);

a)

35

b)

-2

c)

34

d)

38

39.

What is the output of the following code:

#include<stdio.h>

void main()

{

int a=10,b=80,c=45;

printf("%d",a<b>c);

}

a)

0

b)

1

c)

10

d)

Error

40.

What is the output of the following code:

#include<stdio.h>

void main()

{

int a=10,b=-5;

printf("%d",a&&b);

}

a)

1

b)

0

c)

Error

d)

10

e)

-5

41.

What is the output of the following printf


int a=9;

printf("%d",~a);

a)

10

b)

-10

c)

6

d)

-9

42.

What is the output of the following printf


int a=-11;

printf("%d",!a);

a)

0

b)

1

c)

12

d)

10

43.

What is the output of the following printf:


int a=6,b=8;

printf("%d",a^b);

a)

14

b)

0

c)

6

d)

8

44.

What is the output of the following printf:


int a=10;

b=++a;

printf("%d,%d",a,b);

a)

11,11

b)

10,11

c)

11,10

d)

10,10

45.

What is the value of printf:


printf("%d",sizeof(double));

a)

8

b)

10

c)

4

d)

6

46.

Which of the following ternary operator is correct to findout biggest of 3 numbers:

a)

c>a?(c>b?c:b):(a>b?a:b)

b)

b<a?(a>c?a:c):(b<c?b:c)

c)

c<b?(b<a?b:a):(c<a?c:a)

d)

a<b?(b>c?b:c):(a<c?c:a)

47.

What is the proper declaration for an array that has 2 rows and 3 columns?

a)

type arr[2][2];

b)

arr[2][3] type;

c)

type arr[2][3];

d)

type arr[4][3];

48.

How can I store the value 10 into the second row, first column of my array that I have declared as int numbers[10][10]?

a)

int numbers[1][2] = 10;

b)

numbers[1][2] = 10;

c)

numbers[2][3] = 10;

d)

numbers[1][0] = 10

49.



(a)  

50.
a)

Compilation Error

b)

14

c)

13

d)

Garbage Value

51.
a)

321004

b)

3210

c)

01234

d)

400123

e)

432100

52.
a)

1 2 3 4 5 5

b)

1 2 3 4 5 0

c)

1 2 3 4 5 Garbage value

d)

Error

53.

int A[5][4];

What will be the size of above array element ?

(a)  

54.

int A[2][2][2];

What will be the size of above array element ?

(a)  

55.

Pick all correct statements.

a)

int A[][]={1,2,3,4};

b)

int A[2][]={1,2,3,4};

c)

int A[][2]={1,2,3,4};

d)

int A[2][2]={1,2,3,4};

56.

if two strings are identical then function strcmp() returns

a)

0

b)

-1

c)

true

d)

none of these

57.

what will be the output of the program?

#include <stdio.h>

#include<string .h>

void main()

{

char str1[20]="Hello",str2="world";

strcat(str1,str2);

puts(str1);

return 0;

}

a)

Hello

b)

world

c)

Helloworld

d)

none of the above

58.

str1="6/4";

printf("str1");

a)

6/4

b)

str1

c)

None

59.

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

a)

scanf()

b)

printf()

c)

puts()

d)

gets()

60.

int main()

{

char str[25];

scanf("%s", str);

printf("%s",str);

return 0;

}

//input: South Africa

a)

South

b)

South Africa

c)

S

d)

Compiler error

61.

What is the output of C program with strings.?

int main()

{

char str1[]="SMART";

char str2[10];

str2 = str1;

printf("%s",str2);

return 0;

}

a)

SMART

b)

SMART followed by 5 spaces

c)

SMART followed by 4 spaces

d)

can not assign one string to another

62.

What will the output of the following program?

#include <stdio.h>

int main()

{

char str1[] = "College";

char str2[] = "University";

strcpy(str1, str2);

printf("%s", str1);

}

a)

College

b)

University

c)

College University

d)

University College

63.

A string is a ____________ character array.

a)

Null terminated

b)

fully terminated

c)

listed in parenthesis

64.

Guess the output:

void main()

{

  char name[10]=“ECE”;

  printf(“Name is %s”,name);

}

a)

Error

b)

ECE

c)

Name is ECE

d)

warning

65.

What will be the output of below C code?

printf(“%.5s”,name);

a)

will print all the characters

b)

will print the name

c)

will print the 5 characters

66.

Who is father of C Language?

a)

Bjarne Stroustrup

b)

James A. Gosling

c)

Dennis Ritchie

d)

Dr. E.F. Codd

67.

In which of the following function compiler used to read strings with blank space?

a)

getchar()

b)

getche()

c)

gets()

d)

None of the Above

68.

In the standard library of C programming language, which of the following header file is designed for string operations?

a)

string.h

b)

conio.h

c)

dos.h

d)

stdio.h

69.

Full form of ASCII code is ___________.

a)

American Standard Code for Internet Interconnection

b)

American Standard Code for Internet Interchange

c)

American Standard Code for Information Interchange

d)

American Standard Captcha for Information Interchange

70.

Which of the following Converts lowercase characters of a string to uppercase in C?

a)

strupr()

b)

strdup()

c)

export

71.

Which of the following is not logical operator?

a)

&

b)

&&

c)

||

d)

!

72.

Select the wrong way to get a string from the user which is declared as follows:


char str[50];

a)

scanf("%s",&str)

b)

scanf("%s",str)

c)

gets(str)

d)

All are correct

73.

A string is a ____________ character array.

a)

Null terminated

b)

fully terminated

c)

listed in parenthesis

74.

Guess the output:

void main()

{

  char name[10]=“ECE”;

  printf(“Name is %s”,name);

}

a)

Error

b)

ECE

c)

Name is ECE

d)

warning

75.

What will be the output of below C code?

printf(“%.5s”,name);

a)

will print all the characters

b)

will print the name

c)

will print the 5 characters

76.

Who is father of C Language?

a)

Bjarne Stroustrup

b)

James A. Gosling

c)

Dennis Ritchie

d)

Dr. E.F. Codd

77.

In which of the following function compiler used to read strings with blank space?

a)

getchar()

b)

getche()

c)

gets()

d)

None of the Above

78.

In the standard library of C programming language, which of the following header file is designed for string operations?

a)

string.h

b)

conio.h

c)

dos.h

d)

stdio.h

79.

Full form of ASCII code is ___________.

a)

American Standard Code for Internet Interconnection

b)

American Standard Code for Internet Interchange

c)

American Standard Code for Information Interchange

d)

American Standard Captcha for Information Interchange

80.

Which of the following Converts lowercase characters of a string to uppercase in C?

a)

strupr()

b)

strdup()

c)

export

81.

Which of the following is not logical operator?

a)

&

b)

&&

c)

||

d)

!

82.

Select the wrong way to get a string from the user which is declared as follows:


char str[50];

a)

scanf("%s",&str)

b)

scanf("%s",str)

c)

gets(str)

d)

All are correct