Programming in Java - MCQ Assignment - 0
Programming in Java - MCQ Assignment - 0
Programming in Java - MCQ Assignment - 0
PROGRAMMING IN JAVA
Assignment 0
TYPE OF QUESTION: MCQ
Number of questions: 15 Total mark: 15 × 1 = 15
______________________________________________________________________________
QUESTION 1:
In C programming, what is the use of %d format specifier in printf() function?
Correct Answer: b
Detailed Solution:
The %d format specifier in printf() function is used to print integer type value.
____________________________________________________________________________
QUESTION 2:
Consider the following code and answer the questions.
int main()
{
int a[8] = {3, 1, 0, 5, 2, 7, 6, 4};
}
What is the value of a[a[a[3]]]? Select your correct answer from the following options.
Correct Answer: d
Detailed Solution:
Self-explanatory. Trace the result with execution on printing the desired value.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur
____________________________________________________________________________
QUESTION 3:
Which of the following is not a valid identifier in C programming language?
a. 21Guns
b. No
c. yes
d. *p
Correct Answer: a
Detailed Solution:
In C programming language, the identifiers cannot start with a number. *p is valid where it
declares p as a pointer variable, such as int *p;
____________________________________________________________________________
QUESTION 4:
Consider the following function definition:
functionCheck( int a, int b)
{
return (( a < b ) ? 0 : ( a - b ));
}
a. Maximum of x and y.
b. Positive difference of x and y.
c. Sum of x and y.
d. Minimum of x and y.
Correct Answer: d
Detailed Solution:
This function functionCheck(x, functionCheck(x, y)) is to find the
minimum of x and y.
____________________________________________________________________________
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur
QUESTION 5:
What will be the output of the following code?
#include<stdio.h>
int main()
{
int v1 = 40;
int v2 = 0;
printf("%d", myfunc(1, 1)*myfunc(v, 1));
return 0;
}
a. 40
b. 400
c. 440
d. 0
Correct Answer: c
Detailed Solution:
“myfunc(i, j) i##j ” meaning is concatenate second operand to first.
____________________________________________________________________________
QUESTION 6:
To store the string “Javajuly”, how many bytes that a C-compiler will take? Select your
correct answer from the following options.
a. 4 bytes.
b. 5 bytes.
c. 8 bytes.
d. 9 bytes.
Correct Answer: d
Detailed Solution:
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur
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 9 bytes.
________________________________________________________________________
QUESTION 7:
Which of the following operator has the lowest priority ?
a. ++
b. +
c. %
d. ||
Correct Answer: d
Detailed Solution:
The || (Logical OR) has the lowest priority out of ++, + and %.
________________________________________________________________________
QUESTION 8:
In the declaration given below, what is “array”?
int array[20];
a. It is a keyword
b. It is a literal
c. It is an operator
d. It is a pointer
Correct Answer: d
Detailed Solution:
“array” is an identifier here. The name of the array is also a pointer to the starting of an array.
____________________________________________________________________________
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur
QUESTION 9:
What will be the output of the following C code?
#include <stdio.h>
int main()
{
void foo();
printf("1 ");
foo();
}
void foo()
{
printf("2 ");
}
A. 1 2
B. It will give compile-time error
C. 212
D. Depends on the compiler
Correct Answer: a
Detailed Solution:
Self-explanatory. Trace the program by execution.
____________________________________________________________________________
QUESTION 10:
Which of the following is a valid C expression?
Correct Answer: b
Detailed Solution:
int my_num = 100,000;It is Invalid because it has a comma operator in integer number which is not
allowed in C.
int my num = 1000; It is Invalid because space is not allowed in the identifier name in C.
int $my_num = 10000; It is Invalid because The first letter of an identifier should be either a letter or
an underscore.
____________________________________________________________________________
QUESTION 11:
Consider the following declarations:
i. z = x / y + a / b ;
ii. z = a / b * b / a * x ;
iii. z = (x / y) > 1 ? x : y ;
iv. z = (int) (x + b) / a % b ;
Correct Answer: a
Detailed Solution:
Self-explanatory. Trace the program by execution.
____________________________________________________________________________
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur
QUESTION 12:
Consider the following declarations:
#include<stdio.h>
void main()
{
int i, j = 10; y = 0;
for(i = 0; i < j; i++)
while(j) y += j--;
printf(%d”, y);
}
What will be the output of the program? Select your option from the following.
A. 100
B. 10 9 8 … 3 2 1
C. 10+9+8+ … +3+2+1
D. 0
Correct Answer: c
Detailed Solution:
Self-explanatory. Trace the program by execution.
____________________________________________________________________________
QUESTION 13:
A function foo(int) is defined as follows:
int foo(int i) {
int x=1, j = 1;
while (i) {
x *= j;
j++;
if(j<7) continue;
else break;
}
return x;
}
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur
What will be the output of the program? Select your option from the following.
Correct Answer: B
Detailed Solution:
Self-explanatory. Trace the program by execution.
____________________________________________________________________________
QUESTION 14:
Correct Answer: B
Detailed Solution:
All others are object-oriented programming languages.
____________________________________________________________________________
QUESTION 15:
Correct Answer: B
Detailed Solution:
C language does not support parallel execution of programs. Others are well-suited in C.
____________________________________________________________________________
******