0% found this document useful (0 votes)
32 views5 pages

Week-03 July22

Uploaded by

Debasish Sarkar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views5 pages

Week-03 July22

Uploaded by

Debasish Sarkar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

NPTEL Online Certification Courses

Indian Institute of Technology Kharagpur

DATA STRUCTURES AND ALGORITHMS USING JAVA


Assignment 3
TYPE OF QUESTION: MCQ
Number of questions: 10 Total marks: 10× 1 = 10
______________________________________________________________________________

QUESTION 1:

What will be the output of following:


int arr[] = new int[];

System.out. println(arr);

a. Garbage Value
b. Pointer to Address
c. Compile time Error
d. None of the above

Correct Answer: c

Detailed Solution:
The size of the array should be provided during declaration of the array.
____________________________________________________________________________

QUESTION 2:

What is the output of the following code snippet?


int arr[] = new int[5];

System.out. println(arr);

a. Garbage Value
b. Reference Value
c. Compile time Error
d. None of the above

Correct Answer: b

Detailed Solution:
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

Array is created as an object and therefore when printed will return the reference value.
___________________________________________________________________________

QUESTION 3:

What is the output of the following code snippet?

int arr[] = new int[-5];

a. Compilation Error
b. Logical Error
c. Exception
d. None of the above

Correct Answer:c
Detailed Solution:
We cannot declare a negative integer as array size.
We will have NegativeArraySizeException at runtime
_________________________________________________________________________

QUESTION 4:

Is the statement in red a legal statement?


int[] a = new int[30];

int[] b = new int[50];

a = b; // ??

a. Legal Statement
b. Compile time error
c. Runtime error
d. None of these

Correct Answer: a

Detailed Solution:
Compiler Checks only type not the size..
_________________________________________________________
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 5:

Which of the following is not a legal declaration of array?

a. int arr[] = new int[3];


b. int[] arr = new int[3];
c. int arr[] = {1,2,3,4,5};
d. int arr[] = new int[3]{1,2,3};

Correct Answer: d

Detailed Solution:
Declaring size and the array elements simultaneously is not required.
________________________________________________________________________

QUESTION 6:

Which of the following is a linear Data Structure?

a. Array
b. Graph
c. Binary Tree
d. Heap Tree

Correct Answer: a

Detailed Solution:
Array is a linear Data Structure..
___________________________________________________________________________

QUESTION 7:

What will be the output of the given command?


int arr[] = new int[5];
System.out.print(arr[5]);

a. Compile Time Error


b. Garbage Value
c. Reference Address
d. ArrayIndexOutOfBoundsException

Correct Answer: d
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

Detailed Solution:
Array of size 5 has index values 0 to 4. arr[5] is an illegal expression and causes
ArrayIndexOutOfBoundsException.

__________________________________________________________________________

QUESTION 8:

What is the default value of Object type array?


a. 0
b. ““
c. False
d. null

Correct Answer: d

Detailed Solution:
Object type array has default value as null
___________________________________________________________________________

QUESTION 9:

Which of the following returns the length of an Array?

a. length
b. length()
c. size()
d. len()

Correct Answer: a

Detailed Solution:
length is a final variable applicable for arrays. With the help of the length variable, we can obtain
the size of the array.
___________________________________________________________________________

QUESTION 10:

Which of the following statement is ?

a. Size of an array can be declared at runtime


b. Array is a dynamic data structure.
c. Same Array can store different data types
d. Array is a collection of similar types of elements.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

Correct Answer: d

Detailed Solution:
Array is a collection of similar types of elements
___________________________________________________________________________

************END************

You might also like