wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Arrays and Strings in C

Total questions: 32

Worksheet time: 16mins

Name
Class
Date
1.

 

Array can be considered as set of elements stored in consecutive memory locations but having __________.

a)

Same data type

b)

Different data type

c)

Same scope

d)

None of these

2.

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

3.

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

4.
a)

1 2 3 4 5 5

b)

1 2 3 4 5 0

c)

1 2 3 4 5 Garbage value

d)

Error

5.

if two strings are identical then function strcmp() returns

a)

0

b)

-1

c)

true

d)

none of these

6.

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

7.

str1="6/4";

printf("str1");

a)

6/4

b)

str1

c)

None

8.

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

a)

scanf()

b)

printf()

c)

puts()

d)

gets()

9.

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

10.

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

11.

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

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.

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}

16.

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

17.

An array Index starts with.?

a)

-1

b)

0

c)

1

d)

2

18.

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

19.

What is the output of C Program.?

int main()

{

char grade[] = {'A','B','C'}; printf("GRADE=%c, ", *grade); printf("GRADE=%d", grade);

}

a)

GRADE=some address of array, GRADE=A

b)

GRADE=A, GRADE=some address of array

c)

GRADE=A, GRADE=A

d)

Compiler error

20.

What is the output of C program.?

int main() {

char grade[] = {'A','B','C'}; printf("GRADE=%d, ", *grade); printf("GRADE=%d", grade[0]);

}

a)

A A

b)

65 A

c)

65 65

d)

None

21.

What is the output of C program.?

int main()

{

float marks[3] = {90.5, 92.5, 96.5};

int a=0;

while(a<3)

{

printf("%.2f,", marks[a]); a++;

}

}

a)

90.5 92.5 96.5

b)

90.50 92.50 96.50

c)

0.00 0.00 0.00

d)

Compiler error

22.

What is the output of C Program.?

int main() {

int a[3] = {10,12,14};

a[1]=20;

int i=0;

while(i<3)

{ printf("%d ", a[i]);

i++; }

}

a)

20 12 14

b)

10 20 14

c)

10 12 20

d)

Error

23.

What is the output of C program with arrays.?

int main() {

int a[3] = {20,30,40};

int b[3];

b=a;

printf("%d", b[0]);

}

a)

20

b)

30

c)

address of 0th element.

d)

Compiler error

24.

Which is not a built in function

a)

string()

b)

strlen()

c)

strcat()

d)

strcmp()

25.

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

a)

Null

b)

Empty

c)

0

d)

1

26.

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

27.

String is initialized with datatype

a)

float

b)

char

c)

int

d)

double

28.

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

29.

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

30.

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

31.

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

32.

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