13/11/2024, 15:24 Programming in Java - - Unit 3 - Week 0 :
(https://swayam.gov.in) (https://swayam.gov.in/nc_details/NPTEL)
[email protected]
NPTEL (https://swayam.gov.in/explorer?ncCode=NPTEL) » Programming in Java (course)
Course Week 0: Assignment 0
outline Your last recorded submission was on 2024-08-06, 22:27 IST
1) What is the output of the following C++ code snippet? 1 point
About
NPTEL ()
#include <iostream>
How does an using namespace std;
NPTEL
online
course int main() {
work? () int x = 10, y = 20;
int *p = &x;
Week 0 : ()
*p = y;
Practice:
cout << x << " " << y << endl;
Week 0:
Assignment 0 return 0;
(assessment?
}
name=389)
Week 1 : ()
a. 20 20
Week 2 : () b. 10 20
c. 10 10
Week 3 : ()
d. 20 10
Week 4 : ()
2) If A is a 3 x 3 matrix given by: 1 point
Week 5 : ()
Week 6 : ()
Week 7 : ()
https://onlinecourses.nptel.ac.in/noc24_cs105/unit?unit=16&assessment=389 1/6
13/11/2024, 15:24 Programming in Java - - Unit 3 - Week 0 :
Week 8 : ()
Week 9 : ()
Week 10 : ()
What is the determinant of A?
Week 11 : ()
a. 49
Week 12 : () b. 72
c. 54
Books ()
d. -54
Text 3) Given vectors u=(2,3) and v=(4,-1), what is the dot product u⋅v? 1 point
Transcripts
() a. 10
b. 5
c. 11
d. 7
4) Consider the following C++ code snippet. What will be the output? 1 point
#include <iostream>
using namespace std;
void swap(int &a, int &b) {
int temp = a;
a = b;
b = temp;
}
int main() {
int x = 5, y = 10;
swap(x, y);
cout << x << " " << y << endl;
return 0;
}
a. 10 5
b. 5 5
c. 10 10
d. 5 10
https://onlinecourses.nptel.ac.in/noc24_cs105/unit?unit=16&assessment=389 2/6
13/11/2024, 15:24 Programming in Java - - Unit 3 - Week 0 :
5) What will be the output of the following C code? 1 point
#include <stdio.h>
int main() {
int arr[5] = {1, 2, 3, 4, 5};
int *ptr = arr;
printf("%d\n", *(ptr + 3));
return 0;
a. 1
b. 2
c. 3
d. 4
6) What is the modulus of the complex number z=3+4i ? 1 point
a. 5
b. 7
c. 4
d. 3
7) What will be the output of the following C++ code snippet? 1 point
#include <iostream>
using namespace std;
int main() {
int alpha = 10;
int *p = α
cout << *p << endl;
return 0;
a. Address of alpha
b. 10
c. Garbage value
d. Compilation Error
8) In the binomial expansion of (a+b)5, what is the coefficient of the term a3 b2? 1 point
a. 5
https://onlinecourses.nptel.ac.in/noc24_cs105/unit?unit=16&assessment=389 3/6
13/11/2024, 15:24 Programming in Java - - Unit 3 - Week 0 :
b. 10
c. 20
d. 30
9) Given 3 numbers x, y and z. In order to find the maximum using if-then-else: 1 point
if x > y then
if x > z then
max = x
else
max = z
else
________________ #MISSING
max = y
else
max = z
a. if y > z then
b. if y < z then
c. if x > z then
d. if x < z then
10) Which of the following statements correctly initializes an array in C? (Please choose 1 point
All if all are correct)
a. int arr[5] = {1, 2, 3}
b. int arr[] = {1, 2, 3}
c. int arr[5] = {1, 2, 3, 4, 5}
d. All of these
11) What is the output of the following C++ code? 1 point
#include <iostream>
using namespace std;
void fun(int arr[], int n) {
for(int i = 0; i < n; i++) {
arr[i] = arr[i] * arr[i] - arr[i];
}
}
int main() {
https://onlinecourses.nptel.ac.in/noc24_cs105/unit?unit=16&assessment=389 4/6
13/11/2024, 15:24 Programming in Java - - Unit 3 - Week 0 :
int arr[3] = {1, 2, 3};
fun(arr, 3);
for(int i = 0; i < 3; i++) {
cout << arr[i] << " ";
}
cout << endl;
return 0;
}
a. 1 4 9
b. 1 2 3
c. 0 2 6
d. 2 4 6
12) If the sequence of numbers 1 point
2,6,12,20,30,…
continues in the same pattern, what will be the 7th term in the sequence?
a. 56
b. 72
c. 42
d. 48
13) Consider the following C code snippet. What will be the output? 1 point
#include <stdio.h>
void func(int arr[], int size) {
for (int i = 0; i < size; i++) {
arr[i] += 5;
}
}
int main() {
int arr[] = {1, 2, 3, 4, 5};
int size = sizeof(arr) / sizeof(arr[0]);
func(arr, size);
for (int i = 0; i < size; i++) {
printf("%d ", arr[i]);
https://onlinecourses.nptel.ac.in/noc24_cs105/unit?unit=16&assessment=389 5/6
13/11/2024, 15:24 Programming in Java - - Unit 3 - Week 0 :
return 0;
}
a. 1 2 3 4 5
b. 6 7 8 9 10
c. 5 4 3 2 1
d. 6 7 8 9 11
14) In C++, which of the following operators can be overloaded? 1 point
a. :: (scope resolution operator)
b. . (member access operator)
c. + (addition operator)
d. ?: (ternary operator)
15) Which of the following is true about the new keyword in C++? 1 point
a. It allocates memory on the stack
b. It allocates memory on the heap
c. It does not initialize the allocated memory
d. It can only be used with primitive types
Check Answers and Submit
https://onlinecourses.nptel.ac.in/noc24_cs105/unit?unit=16&assessment=389 6/6