Week 0 Assignment

Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

NPTEL Online Certification Courses

Indian Institute of Technology Kharagpur

PROGRAMMING IN JAVA
Assignment -- 0
TYPE OF QUESTION: MCQ
Number of questions: 15 Total mark: 15×1 = 15
______________________________________________________________________________

QUESTION 1:
What is the data type that occupies the least storage in C language?

a. float
b. char
c. double
d. int

Correct Answer: b

Detailed Solution:
Character data type allows a variable to store only one character which is of one byte, that is,
eight bits. In general, int takes 2 bytes, float takes four bytes and double takes eight bytes.

______________________________________________________________________________

QUESTION 2:
What is the output of the code segment in C?

#include <stdio.h>
int main()
{
enum Nptel { July = 0, Aug, Dec};
enum Nptel course = Dec;
if( course == 0)
printf("course is in July");
else if(course == 1)
printf("course is in Aug");
if(course == 2)
printf("course is in Dec");
}

a. course is in July
b. course is in Aug
c. course is in Dec
d. Compilation error
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

Correct Answer: c

Detailed Solution:
Enumeration data type consists of named integer constants as a list. It start with 0 (zero) by
default and value is incremented by 1 for the sequential identifiers in the list.

____________________________________________________________________________

QUESTION 3:
What is the output of this program?

#include <stdio.h>

int main() {
int i;

for (i=0;i<10;i++);
{
printf("%d ",i);
}

}
a. 0123456789
b. 10
c. 9
d. Runtime Error

Correct Answer: b

Detailed Solution:
Due to semicolon, for loop is in self loop and then i value is printed.

______________________________________________________________________________

QUESTION 4:

What does the following declaration mean?

int (*ptr)[10];

a. ptr is array of pointers to 10 integers.


b. ptr is a pointer to an array of 10 integers.
c. ptr is an array of 10 integers.
d. ptr is a pointer to a two-dimensional array.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

Correct Answer: b

Detailed Solution:
This is the declaration of pointer to an array of size 10.
_____________________________________________________________________

QUESTION 5:
In C, if you 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.
d. Address of the last element of the array.

Correct Answer: c

Detailed Solution:
When we pass an array as a function argument, the base address of the array will be passed.

______________________________________________________________________________

QUESTION 6:
Which of the following statements(s) is/are not true?
a. Assembler translates a program in high level programming language into a code in an
assembly language.
b. Compiler translates a program in high level programming language into a code in a
machine language.
c. Interpreter translates a program in high level programming language into a code in a
machine language.
d. A program in C is compiled whereas a program in C++ is interpreted.

Correct Answer: a, d

Detailed Solution:
All high level language (in general) is compiled to code in machine level language. The same strategy is
followed in both C and C++ programming languages.

_________________________________________________________________________

QUESTION 7:
Choose the most appropriate statement(s) in the following.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

a. C, C++ and Java all are high-level programming languages.


b. C and C++ both support pointer to reference a location of any variable.
c. A C program is a collection of functions whereas C++ is a collection of both functions and
classes.
d. C provides dynamic memory allocation whereas C++ does not support the same.

Correct Answer: a, b

Detailed Solution:
C program is a collection of functions whereas C++ is a collection of classes. C provides malloc()
and calloc()functions for dynamic memory allocation, and free() for memory de-allocation. C++ provides
new operator for memory allocation and delete operator for memory de-allocation.
______________________________________________________________________________

QUESTION 8:
Before the execution of a program, an operating system should
a. load the program into cache memory.
b. load the program into register in CPU.
c. load the program into primary memory.
d. Run the program from secondary memory

Select the correct option(s) in the above.

Correct Answer: c

Detailed Solution:
The computer can manipulate only data that is in main memory. So, every program you execute
and every file you access must be copied from a storage device into main memory.

______________________________________________________________________________

QUESTION 9:
Consider the following piece of code in C programming language.

#include <stdio.h>
int main() {
int i=10;
for(int i=0;i<=20;i++)
i++;
printf("%d",i);
return 0;
}
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

If you run this program, then which of the following statement(s) is (are) true?

a. The program will print the value of i as 10.


b. The program will print the value of i as 20.
c. The program will print the value of i as 21.
d. The loop will execute exactly 10 times.

Correct Answer: a

Detailed Solution:
The i in for loop has local scope and it is within the for block. The variable i outside the block is
the scope of the variable in the printf statement.
____________________________________________________________________________

QUESTION 10:
What is the output of the following code segment?

int i = 1;
printf(“%d + %d”,i++,++i);

a. 1+2
b. 2+3
c. 2+2
d. 1+1

Correct Answer: b

Detailed Solution:
It is the concept of pre-increment and post-increment. The evaluation is done from right-to-left
and printf will print the value from left-to-right.

______________________________________________________________________________

QUESTION 11:

To store the string “Java”, how many bytes that a C compiler will take?

a. 4 bytes.
b. 5 bytes.
c. 8 bytes.
d. 9 bytes.

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

Detailed Solution:
A C string is as long as the number of characters between the beginning of the string and the
terminating null character. So it will take 5 bytes.

_____________________________________________________________________

QUESTION 12:
Which of the following statement(s) to declare an array, say ‘a’ is(are) not valid in C
programming language?

a. int a[m]; //m is an integer variable


b. int *a;
c. int a[ ]={1,2,3,4,5};
d. int a[10000];

Correct Answer: a, b

Detailed Solution:
C language needs the size of the array at the time of compilation. Since the value of m is not
known at the time of compilation, C compiler will give compilation error. Further, note that *a is
a pointer to an integer variable, it can point to an array but not actually an array.
______________________________________________________________________________

QUESTION 13:
Which of the following is not a valid keyword in C?

a. auto
b. void
c. switch
d. malloc

Correct Answer: d

Detailed Solution:
1. Keywords are those words whose meaning is already defined by Compiler
2. Cannot be used as Variable Name
3. There are 32 Keywords in C
4. C Keywords are also called as Reserved words

The name "malloc" stands for memory allocation. It is not a keyword, rather is a library fiction
defined in <stdlib.h> in C programming language. The malloc() function reserves a block of
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

memory of the specified number of bytes. And, it returns a pointer of type void which can be
casted into pointer of any form.
______________________________________________________________________________

QUESTION 14:
What result the following macro will produce in a statement in C programming language?

#include <stdio.h>
#define square(x) x*x
int main() {
int x=36/square(6);
printf("%d",x);
return 0;
}

a. 36
b. 1
c. 0
d. 6

Correct Answer: a

Detailed Solution:
The calculation is 36/6*6. This will be equivalently (36/6)*6 because both / and * are of same
precedence and with left-to-right associativity.

________________________________________________________________

QUESTION 15:
Which of the following language is not based on object-oriented paradigms?

a. C
b. C++
c. Java
d. Python

Correct Answer: a

Detailed Solution:
C is not based on 'object-oriented' paradigm rather than function-oriented paradigm. It has
no concept of classes, objects, polymorphism, and inheritance.

You might also like