wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

IP Unit 3

Total questions: 54

Worksheet time: 28mins

Name
Class
Date
1.

How do you initialize an array in C?

a)

int arr[3] = (1,2,3);

b)

int arr(3) = {1,2,3};

c)

int arr[3] = {1,2,3}

d)

int arr(3) = (1,2,3)

2.

What is the output of C Program.?

int main() {

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

int b[4] = {5,6,7,8};

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

}

a)

1,5

b)

2,6

c)

0,0

d)

Error

3.

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

4.

An array elements are always stored in ________ memory locations.

a)

sequential

b)

Random

c)

Sequential and Random

d)

None of the above

5.

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}

6.

Arrays are structures that hold multiple variables of the _____________ data type

a)

int data type

b)

char data type

c)

same data type

d)

different data type

7.

What is the index number of the last element of an array with 29 elements?

a)

29

b)

28

c)

0

d)

Programmer-defined

8.

Which of the following is a two-dimensional array?

a)

array anarray[20][20];

b)

int anarray[20][20];

c)

int array[20, 20];

d)

char array[20];

9.

What is an array in C programming?

a)

A method for sorting data

b)

A type of function

c)

A collection of different data types

d)

A sequential collection of similar data items

10.

How is a single-dimensional array declared in C?

a)

size array_name[datatype];

b)

datatype array_name[size];

c)

array_name[size] datatype;

d)

datatype[size] array_name;

11.

What is the index range for an array of size n?

a)

0 to n

b)

1 to n-1

c)

0 to n-1

d)

1 to n

12.

What does the scanf() function do in C?

a)

Declares variables

b)

Prints output to the screen

c)

Allocates memory for arrays

d)

Reads input from the keyboard

13.

What is the output of printf("%d", a[0]); if a is an array of integers?

a)

The first element of the array

b)

The size of the array

c)

The address of the array

d)

The last element of the array

14.

Which of the following statements are correct about an array?

1:The array int num[26]; can store 26 elements.

2:The expression num[1] designates the very first element in the array.

3:It is necessary to initialize the array at the time of declaration.

4:The declaration num[SIZE] is allowed if SIZE is a macro.

a)

1

b)

1,4

c)

2,4

d)

2,3

15.

To access an array element, use the array name and the element's ___________.

a)

data type

b)

subscript

c)

value

d)

name

16.

In an array, every element has the same

a)

data type

b)

memory location

c)

subscript

d)

all of the above

17.

Given the following declaration, where is the value 77 stored in the scores array?

int scores[] = {83, 62, 77, 97, 86}

a)

scores[0]

b)

scores[1]

c)

scores[2]

d)

scores[3]

18.

Before using an array its type and dimension must be declared?

a)

True

b)

False

19.

In general, the index of the first element in an array is __________

a)

0

b)

-1

c)

2

d)

1

20.

What is meaning of following

declaration ?

int arr[20];

a)

Array of size 20 that can have integer address

b)

Array of Size 20

c)

Integer Array of size 20

d)

None of these

21.

what will be the output of the following code snippet

#include <stdio.h>

int main()

{

int a = 3, b = 5;

int t = a;

a = b;

b = t;

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

return 0;

}

a)

3 5

b)

3 3

c)

5 5

d)

5 3

22.

What is the output of the following code snippet?

#include <stdio.h>

int main() {

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

            int sum = 0;

            for(int i = 0; i < 4; i++) {

                sum += a[i];

            }

            printf("%d", sum);

            return 0;

}

a)

1

b)

4

c)

20

d)

10

23.
How do you access elements in an array in C?
a)
By using the index of the element
b)
By using the size of the array
c)
By using a loop
d)
By using a pointer
24.
What is an array in C?
a)
A collection of homogeneous data elements
b)
A collection of heterogeneous data elements
c)
A single data element
d)
A collection of keys and values
25.

Arrays are structures that hold multiple variables of the _____________ data type

a)

int data type

b)

char data type

c)

same data type

d)

different data type

26.

Array locations are considered to be

a)

contiguous

b)

adjacent

c)

randon

d)

dynamic

27.

An array item is referenced by its

a)

index

b)

value

c)

variable

d)

type

28.

Which statement allows the user to input an element into an array?

a)

scanf("%d', &num);

b)

scanf("%d', &num[0]);

c)

num[0] = 20;

d)

int num[] = {0};

29.

An array does not need a defined size.

a)

True

b)

False

30.

which string library function allows you to compare two words?

a)

strlen

b)

strcmp

c)

strrev

d)

strcpy

31.

if two strings are identical then function strcmp() returns

a)

0

b)

-1

c)

true

d)

none of these

32.

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

33.

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

34.

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

35.

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

36.

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

37.

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

38.

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

39.

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

40.

str1="6/4";

printf("str1");

a)

6/4

b)

str1

c)

None

41.

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

42.

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

43.

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]

44.

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

a)

3

b)

4

c)

2

d)

1

45.
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
46.

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

47.

Which is not a built in function

a)

string()

b)

strlen()

c)

strcat()

d)

strcmp()

48.

String is initialized with datatype

a)

float

b)

char

c)

int

d)

double

49.
Which string method helps find length of string?
a)
stringLength()
b)
strlen
c)
strdup
d)
both i & ii
50.

The "\n" character does which of the following operations?

a)

Double line spacing

b)

Character deletion

c)

Character backspace

d)

Places cursor on the next line

51.

Which of the following is the correct operator to compare two variables?

a)

equal

b)

=

c)

:=

d)

==

52.

Every variable must be -------------- before it is used.

a)

executed

b)

defined

c)

declared

d)

identified

53.

________to be included to use mathematical functions sqrt()

a)

#include<conio.h>

b)

#include<string.h>

c)

#include<math.h>

d)

#include<stdio.h>

54.

_______________to be included to use standard I/O functions : prinf(),scanf()

a)

#include<conio.h>

b)

#include<stdio.h>

c)

#include<string.h>

d)

#include<math.h>