Programming in Modern C++ | NPTEL 2022 | Week 0 Assignment Solutions

This set of MCQ(multiple choice questions) focuses on the Programming in Modern C++ NPTEL 2022 Week 0 Assignment Solutions.

Programming in C++ is so fundamental that all companies dealing with systems as well as application development (including web, IoT, embedded systems) have a need for the same. These include – Microsoft, Samsung, Xerox, Yahoo, Oracle, Google, IBM, TCS, Infosys, Amazon, Flipkart, etc. This course would help industry developers to be up-to-date with the advances in C++ so that they can remain at the state-of-the-art.

Course layout (Answers link)

Answers COMING SOON! Kindly Wait!

Week 0: Assignment answers
Week 1: Programming in C++ is Fun
Week 2: C++ as Better C.
Week 3: OOP in C++.
Week 4: OOP in C++. 
Week 5: Inheritance.
Week 6: Polymorphism. 
Week 7: Type Casting.
Week 8: Exceptions and Templates.
Week 9: Streams and STL
Week 10: Modern C++
Week 11: Lambda and Concurrency.
Week 12: Move, Rvalue and STL Containers.

NOTE: You can check your answer immediately by clicking show answer button. Programming in Modern C++ NPTEL 2022 Week 0 Assignment Solution” contains 15 questions.

Now, start attempting the quiz.

Programming in Modern C++ NPTEL 2022 Week 0 Assignment Solutions

Q1. Consider the below code snippet.

#include<stdio.h>

int main() {
    typedef double num[3];
    num array[5] = {1, 2, 3, 4, 5, 6}; // LINE-1
    printf("%u", sizeof(array));
    printf(" %.2f", array[1][1]);
    return 0;
}

What will be the output/error (sizeof(double) = 8 bytes)?

a) 40 2.00
b) 120 5.00
c) 120 2.00
d) Compilation error at LINE-1

Answer: b) 120 5.00

Q2. Consider the following code segment.

#include<stdio.h>

enum Covid_prevention {
   Sanitizer = 1,
   Wear_mask = 2,
   Soc_distance = 4
};

int main() {
   int myCovidPrevention = Wear_mask | Soc_distance;
   printf("%d", myCovidPrevention);
   return 0;
}

What will be the output?

a) 2
b) 4
c) 6
d) 8

Answer: c) 6

Q3. Consider the below program.

#include<stdio.h>

int main() {
    int x = 1;
    switch(x)
    {
       case x:
          printf("case 1 ");
          break;
       case x + 1:
          printf("case 2 ");
          break;
       default:
          printf("default block");
          break;
    }
    return 0;
}

What will be the output/error?

a) case 1
b) case 2
c) default block
d) Compilation error: ‘x’ expected to be an integer or a character constant

Answer: d) Compilation error: ‘x’ expected to be an integer or a character constant

Q4. Consider the following linked list:
I -> I -> T -> K -> G -> P
What is the output of the following function when it is called with the head of the list?

void fun(struct node* start) {
     if(start == NULL)
          return;
     printf("%c ", start->data); // Considering data is of 'char' type
     if(start->next != NULL)
          fun(start->next->next);
     printf("%c ", start->data);
} 

a) I T G I G
b) I T G G
c) I T G G T I
d) I T G I T G

Answer: c) I T G G T I

Q5. A single array A[1..MAXSIZE] is used to implement two stacks. The two stacks grow from opposite ends of the array. Variables t1 and t2 (t1 < t2) point to the location of the topmost element in each of the stacks. If the space is to be used efficiently, the condition for stack full is:

a) (t1 = MAXSIZE/2) and (t2 = MAXSIZE/2+1)
b) t1 + t2 = MAXSIZE
c) (t1 = MAXSIZE/2) or (t2 = MAXSIZE)
d) t1 = t2 – 1

Answer: d) t1 = t2 – 1

Programming in Modern C++ NPTEL Assignment Solutions

Q6. Consider the following code segment.

void fun(Queue *que) {

    Stack Stk;
    while(!isEmpty(que)) {

        push(&Stk, deQueue(que));
    }
    
    while(!isEmpty(&Stk)) {
        enQueue(que, pop(&Stk));
    }
}

where push and pop are two standard functionalities of stack data structure. Similarly, enQueue and deQueue are two standard functionalities of queue data structure to insert and delete the items respectively. And isEmpty checks if the stack or the queue is empty or not.
What does the above function do?

a) Remove the last element from que
b) Reverse the elements in the que
c) Keeps the que unchanged
d) Makes que empty

Answer: b) Reverse the elements in the que

Q7. Consider the below code segment.

#include<stdio.h>

int main() {
    int x = 1;
    int y;
    y = (x=x+5, x*5);
    printf("%d", y);
    return 0;
}

What will be the output?

a) 25
b) 30
c) 6
d) 5

Answer: b) 30

Programming in Modern C++ NPTEL Assignment Solutions

Q8. Consider a three-dimensional array arr[5][10][20]. An element from this array can be represented as arr[i][j][k] where 0<=i<=4, 0<=j<=9 and 0<=k<=19. How can you write arr[2][6][10] in an equivalent pointer expression?

a) ((**(*a+2)+6)+10)
b) (**(*(a+2)+6)+10)
c) (*(**(a+2)+6)+10)
d) *(*(*(a+2)+6)+10)

Answer: d) *(*(*(a+2)+6)+10)

Programming in Modern C++ NPTEL Assignment Solutions

Q9. Consider the code segment below.

#include<stdio.h>

int main() {
     int *p, n = 5;
     p = &n;
     *p += 1;

     printf("%d,%d", *p, n);

     return 0;
}

What will be the output?

a) 5,5
b) 5,6
c) 6,5
d) 6,6

Answer: d) 6,6

Q10. Consider the code segment below.

#include<stdio.h>

struct result {
     char subject[20];
     int mark;
};

int main() {
     struct result r[] = {
         {"Maths", 95},
         {"Science", 93},
         {"English", 80}
     };
     printf("%s ", r[1].subject);
     printf("%d", (*(r+2)).mark);

     return 0;
}

What will be the output?

a) Science 80
b) Science 93
c) English 80
d) English 93

Answer: a) Science 80

Programming in Modern C++ NPTEL Assignment Solutions

Q11. Consider the code segment below.

#include<stdio.h>

void teller1(char* msg) {
    printf("teller1: %s\n", msg);
}
void teller2(char* msg) {
    printf("teller2: %s\n", msg);
}
void teller3(char* msg) {
    printf("teller3: %s\n", msg);
}

_ _ _ _ _ _ _ _ _ _ _ _      // LINE-1
void caller(char *msg, F_PTR fp) {
    fp(msg);
}

int main() {
    caller("Hello", &teller1);
    caller("Hi", &teller2);
    caller("Good Morning", &teller3);

    return 0;
}

Identify the correct option to fill in the blank at LINE-1, such that the output is:
teller1: Hello
teller2: Hi
teller3: Good Morning

a) void (*F_PTR) (char*);
b) typedef void (*F_PTR) (char*);
c) void *F_PTR(char*);
d) typedef void (*f_ptr) (char*) F_PTR;

Answer: b) typedef void (*F_PTR) (char*);

Q12. Consider the code segment below.

int main() {
    int array[] = {10, 20, 30, 40, 50};
    int *ip, i;

    for(ip = array + 4, i = 0; i < 5; i++)
        printf("%d ", ______);     // LINE-1

    return 0;
}

Identify the correct option/s to fill in the blank at LINE-1, such that the output is:
50 40 30 20 10

a) -i[ip]
b) ip[-i]
c) -ip[i]
d) (-i)[ip]

Answer: b), d)

Q13. Consider the code segment below.
Assume that the sizeof(int) = 4

#include<stdio.h>

union uData {
    int a;
    int b;
};

struct sData {
    union uData c;
    int d;
};

int main() {
    struct sData da = {10, 20};

    printf("%ld ", sizeof(da));
    printf("%d %d %d", da.c.a, da.c.b, da.d);

    return 0;
}

What will be the output?

a) 8 10 10 20
b) 16 10 20 <garbage-value>
c) 16 10 <garbage-value> 20
d) 8 10 <garbage-value> 20

Answer: a) 8 10 10 20

Q14. Consider the code segment below.

#include<stdio.h>

int main() {
    int x = 8, y, z;

    y = --x;
    z = x--;

    printf("%d %d %d", x, y, z);

    return 0;
}

What will be the output?

a) 8 7 7
b) 8 7 6
c) 6 7 7
d) 6 7 6

Answer: c) 6 7 7

Q15. Consider the code segment below.

#include<stdio.h>

int main() {
    int p = 5, q = 6;

    printf("%d ", ++(p+q+5));
  
    return 0;
}

What will be the output/error?

a) 35
b) 36
c) 41
d) Compilation error: lvalue required as increment operand

Answer: d) Compilation error: lvalue required as increment operand

>> Next- Programming in Modern C++ Week 1 Assignment Solutions


DISCLAIMER: Use these answers only for the reference purpose. Quizermania doesn't claim these answers to be 100% correct. So, make sure you submit your assignments on the basis of your knowledge.

NPTEL answers: Problem solving through programming in C

Programming in Java NPTEL week 1 quiz answers

NPTEL – Python for Data Science assignment solutions

Nptel – Deep Learning assignment solutions

The above question set contains all the correct answers. But in any case, you find any typographical, grammatical or any other error in our site then kindly inform us. Don’t forget to provide the appropriate URL along with error description. So that we can easily correct it.

Thanks in advance.

For discussion about any question, join the below comment section. And get the solution of your query. Also, try to share your thoughts about the topics covered in this particular quiz.

1 thought on “Programming in Modern C++ | NPTEL 2022 | Week 0 Assignment Solutions”

Leave a Comment

Your email address will not be published. Required fields are marked *