wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Quiz-6-Strings-sec-G

Total questions: 93

Worksheet time: 1hrs 13mins

Name
Class
Date
1.

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

2.

What is the Format specifier used to print a String or Character array in C Printf or Scanf function.?

a)

%d

b)

%f

c)

%s

d)

%c

3.

What is the output?

int main()

{

char str[]={'B','M','E','\0'};

printf("%s",str);

return 0;

}

a)

BME

b)

BME with garbage value at the end

c)

BME\0

d)

error

4.

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

5.

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

6.

How do you accept a Multi Word Input in C Language.?

a)

scanf()

b)

gets()

c)

getc()

d)

finds()

7.

Any function working with String knowns the String has ended when it encounters

a)

null character

b)

Empty space

c)

"\1"

d)

pointer

8.

What is the output of C Program with Strings.?


int main()

{

char ary[]="Discovery Channel";

printf("%s",ary);

return 0;

}

a)

D

b)

Discovery Channel

c)

Discovery

d)

Compiler error

9.

Size of the array need not be specified, when

a)

Initialization is a part of definition

b)

It is a formal parameter

c)

It is a declaration

d)

All of the above

10.

An array Index starts with.?

a)

-1

b)

0

c)

1

d)

2

11.

str1="6/4";

printf("str1");

a)

6/4

b)

str1

c)

None

12.

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 };

13.

An array elements are always stored in ________ memory locations.

a)

sequential

b)

Random

c)

Sequential and Random

d)

None of the above

14.

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

15.

if two strings are identical then function strcmp() returns

a)

0

b)

-1

c)

true

d)

none of these

16.

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

17.

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}

18.

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

19.

An array Index starts with.?

a)

-1

b)

0

c)

1

d)

2

20.

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

21.

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

22.

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

a)

7.9

b)

9.2

c)

7.3

d)

0.5

23.

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

a)

Integer and string

b)

Item

c)

Element

d)

Elephant

24.

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

25.

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]

26.

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

27.

The fastest data access is provided using __________

a)

Caches

b)

DRAM’s

c)

SRAM’s

d)

Registers

28.

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

29.

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

30.

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

31.

What is the output of the following printf


int a=9;

printf("%d",~a);

a)

10

b)

-10

c)

6

d)

-9

32.

What is the output of the following printf


int a=-11;

printf("%d",!a);

a)

0

b)

1

c)

12

d)

10

33.

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

34.

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

35.

What is the value of printf:


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

a)

8

b)

10

c)

4

d)

6

36.

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)

37.

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

38.

Which built in function is used to convert string to lowercase

a)

strlen()

b)

strlwr()

c)

strcmp()

d)

strrev()

39.

Which is not a built in function

a)

string()

b)

strlen()

c)

strcat()

d)

strrev()

40.

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

a)

Null

b)

Empty

c)

0

d)

1

41.

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

42.

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

a)

scanf()

b)

gets()

c)

printf()

d)

puts()

43.

The library function used to copy a string to another is

a)

strncpy()

b)

strcmp()

c)

strcpy()

d)

strchr()

44.

String is initialized with datatype

a)

float

b)

char

c)

int

d)

double

45.

Strcat() function adds null character

a)

Only if there is space

b)

Always

c)

Depends on the standard

d)

Depends on the compiler

46.

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

47.

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

48.

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

49.

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

50.

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

51.

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

52.

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

53.

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

54.

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

55.

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

56.

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

a)

strstr()

b)

strrev()

c)

strlen()

d)

strcat()

57.

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

a)

7.9

b)

9.2

c)

7.3

d)

0.5

58.

Given the code, what is the value of things.length ?

a)

4

b)

3

c)

12

d)

7

59.

Given the following:

double [][] stuff ;

Which of the following statements constructs an array with 5 rows of 7 columns each and assign its reference to stuff ?

a)

stuff = new stuff[5][7] ;

b)

stuff = new double[5][7] ;

c)

new stuff = double[5][7] ;

d)

stuff = double new[5][7] ;

60.

Given the code, which of the following fragments prints out every element of items?

a)
b)
c)
d)
61.

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

a)

Integer and string

b)

Item

c)

Element

d)

Elephant

62.

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

63.

Why are arrays useful?

a)

It saves storage space storing under one name

b)

You can store integers and strings together

c)

You can store thing related on different topics

d)

You may have lots of related data that you don't want to store separately

64.

Which of the following statements correctly declares a two-dimensional integer array?

a)

int Matrix[ ] = new int[5,4];

b)

int Matrix[ ]; Matrix = new int[5,4];

c)

int Matrix[ ][ ] = new int[5][4];

d)

int Matrix[ ][ ] = int[5][4];

65.

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]

66.

What would the statement a[1].length return?

a)

3

b)

4

c)

2

d)

1

67.
What value is at index 1 in this array?  String[] names = {"Mack", "Dennis", "Dee", "Charlie"};
a)
Mack
b)
Dennis
c)
Dee
d)
Charlie
68.
True or False:  An array can be store different types of data (like store both doubles and ints).
a)
True
b)
False
69.
A two-dimensional array is a ___________ that contains multiple fields of data that are interrelated to a single record.  It field is referenced by x and y coordinates, often referred to as rows and columns.
a)
list
b)
cube
c)
table
d)
none of the above
70.
An array declaration contains _______________________ after its array name.
a)
an assignment operator
b)
keyword new
c)
a data type and rectangle brackets with a numeric size inside it
d)
all of the above
71.

An array elements are always stored in ________ memory locations.

a)

sequential

b)

Random

c)

Sequential and Random

d)

None of the above

72.

What will be the output of the following program?

#include <stdio.h>


int main()


{


char str1[] = "Sona BME";


char str2[] = "Sona BME";


printf("%d" ,(strcmp(str1, str2)));


}

a)

0

b)

1

c)

-1

d)

error

73.

What will be the output of the following program?

#include <stdio.h>


int main()


{

char str1[] = "Salem";


char str2[] = "Bangalore";


printf("%d" ,(strcmp(str1, str2)));


}

a)

0

b)

-1

c)

1

d)

Compile time Error

74.

What will be the output of the following program?

#include <stdio.h>


int main()


{

char str1[] = "Australia";


char str2[] = "India";


printf("%d" ,(strcmp(str1, str2)));


}

a)

0

b)

-1

c)

1

d)

run time error

75.

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

76.

What will the output of the following program?

#include <stdio.h>

int main()

{

char str1[] = " Sona College";

char str2[] = "Sona University";

strcpy(str1, str2);

printf("%s", str2);

}

a)

Sona College

b)

Sona University

c)

Sona College Sona University

d)

Sona University Sona College

77.

What will be thee output of the following program?

#include <stdio.h>

int main()

{

char str[] = " Have a Good Day ! ";

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

}

a)

20

b)

13

c)

19

d)

18

78.

What will be the output of the following C code?

#include <stdio.h>

int main()

{

char str1[] = "BioMedical ";

char str2[] = "Engineering";

strcat(str1, str2);

printf("%s ", str1);

}

a)

BioMedical

b)

BioMedical Engineering

c)

BioEngineering

d)

Engineering

79.

Which of the following is true about strcat function?

Strcat() function adds null character

a)

Only if there is space

b)

Always

c)

Depends on the standard

d)

Depends on the compiler

80.

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.

81.

Choose a correct statement about C String

a)

Character array, ary is a string

b)

ary has no Null character at the end

c)

String size is not mentioned

d)

String can not contain special characters

82.

What is the Format specifier used to print a String or Character array in C Printf or Scanf function.?

a)

%d

b)

%f

c)

%s

d)

%c

83.

What is the output of C Program with Strings.?

int main()

{

char str[]={'B','M','E'};

printf("%s",str);

return 0;

}

a)

BME

b)

B

c)

E

d)

BME with garbage value at the end

84.

What is the output?

int main()

{

char str[]={'B','M','E','\0'};

printf("%s",str);

return 0;

}

a)

BME

b)

BME with garbage value at the end

c)

BME\0

d)

error

85.

How to convert the following character array into string?


char ary[]={'B','M','E'};

a)

ary[3]=0;

b)

ary[3]='\0';

c)

declaration as: char ary[]={'B','M','E','\0'};

d)

All of the given options

86.

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

87.

What is the output of the following program?

int main()

{

char str1[]="SMART";

str1="Smart and Brilliant";

printf("%s",str1);

return 0;

}

a)

SMART

b)

Smart and Brilliant

c)

SMART and Brilliant

d)

Compile time Error

88.

What is the correct syntax for initializing a string in C?

a)

char str[10] = {'H', 'e', 'l', 'l', 'o', '\0'};

b)

char str[10] = "Hello";

c)

char str[] = {'H', 'e', 'l', 'l', 'o', '\0'};

d)

char str[] = "Hello";

89.

Comment on the following pointer declaration?

int *p, x;

a)

p is a pointer to integer, x is not

b)

p and x, both are pointers to integer

c)

p is pointer to integer, x may or may not be

d)

p and x both are not pointers to integer

90.

If we pass an array as an argument to a function, what actually gets passed?

a)

Value of elements in array

b)

First element of the array

c)

Base address of the array i.e., the address of the first element

d)

Address of the last element of array

91.

what is the output of the following program?

a)

5

b)

15

c)

20

d)

0

92.

What will be the output of the following code snippet?

a)

30

b)

29

c)

36

d)

34

93.

What will be the output of the following code snippet?

a)

18

b)

20

c)

17

d)

25