wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

9.4.25 Mentoring quiz

Total questions: 20

Worksheet time: 23mins

Name
Class
Date
1.
Code executed based on a condition being true
a)
Sequence
b)
Selection
c)
Iteration
d)
Variable
2.

What does the following code do? myAge = int (myAge)

a)

Converts the var (variable) myAge to a string

b)

Converts the var (variable) myAge to a integer

c)

Converts the var (variable) myAge from a integer to a string

d)

Converts the var (variable) myAge to if statement

3.
What will the output be from the following code?
print("Hello world!" * 2)
a)
TypeError
b)
Hello world world!
c)
Hello world!Hello world!
d)
Hello world! * 2
4.

Which paradigm dictates WHAT should be done but not HOW it should be done?

a)

Declarative

b)

Imperative

c)

Object Oriented

d)

Low level

5.

What is the output of C Program.?

int main()

{

int a=5;

while(a >= 3);

{

printf("RABBIT\n");

break;

}

printf("GREEN");

return 0;

}

a)

GREEN

b)

RABBIT GREEN

c)

RABBIT is printed infinite times

d)

None of the above

6.

What is the output of C Program.?

int main()

{

int a=25;

while(a <= 27)

{

printf("%d ", a);

a++;

}

return 0;

}

a)

25 25 25

b)

25 26 27

c)

27 27 27

d)

Compiler error

7.

Choose a correct C Statement.

a)

a++ is (a=a+1) POST INCREMENT Operator

b)

a-- is (a=a-1) POST DECREMENT Operator

--a is (a=a-1) PRE DECREMENT Operator

c)

++a is (a=a+1) PRE INCREMENT Operator

d)

All the above.

8.

In the following loop construct, which one is executed only once always.

for(exp1; exp2; exp3)

a)

exp1

b)

exp3

c)

exp1 and exp3

d)

exp1,exp2 and exp3

9.

What is the value of the postfix expression 6 3 2 4 + – *:

a)

1

b)

14

c)

74

d)

-18

10.

What does the following function do for a given Linked List with first node as head?

void fun1(struct node* head)

{

if(head == NULL)

return;

fun1(head->next);

printf("%d ", head->data);

}

a)

a) Prints all nodes of linked lists

b)

b) Prints all nodes of linked list in reverse order

c)

c) Prints alternate nodes of Linked List

d)

d) Prints alternate nodes in reverse order

11.

Consider the following operation performed on a stack of size 5.

Push(1);

Pop();

Push(2);

Push(3);

Pop();

Push(4);

Pop();

Pop();

Push(5);

a)

4

b)

3

c)

2

d)

1

12.

Consider the following definition in c programming language.

struct node { int data; struct node next; }

typedef struct node NODE;

NODE *ptr;

Which of the following c code is used to create new node?

a)

ptr = (NODE*)malloc(sizeof(NODE));

b)

ptr = (NODE*)malloc(NODE);

c)

ptr = (NODE*)malloc(sizeof(NODE*));

d)

ptr = (NODE)malloc(sizeof(NODE));

13.

What does the following function do for a given Linked List with first node as head?

void fun1(struct node* head)

{ if(head == NULL)

return;

fun1(head->next);

printf("%d ", head->data); }

a)

Prints all nodes of linked lists

b)

Prints all nodes of linked list in reverse order

c)

Prints alternate nodes of Linked List

d)

Prints alternate nodes in reverse order

14.

What is the output of following function for start pointing to first node of following linked list? 1->2->3->4->5->6

void fun(struct node* start)

{

if(start == NULL)

return;

printf("%d ", start->data);

if(start->next != NULL )

fun(start->next->next);

printf("%d ", start->data);

}

a)

1 4 6 6 4 1

b)

1 3 5 1 3 5

c)

1 2 3 5

d)

1 3 5 5 3 1

15.

Assume that the operators +,-, X are left associative and ^ is right associative.

The order of precedence (from highest to lowest) is ^, X, +, -.

The postfix expression for the infix expression

a + b X c – d ^ e ^ f is?

a)

abc X+ def ^^ –

b)

abc X+ def ^^ –

c)

ab+c Xd – e ^f^

d)

-+aXbc^ ^def

16.

After performing these set of operations, what does the final list look contain? InsertFront(10);

InsertFront(20);

InsertRear(30);

DeleteFront();

InsertRear(40);

InsertRear(10);

DeleteRear();

InsertRear(15);

display();

a)

10 30 10 15

b)

20 30 40 15

c)

20 30 40 15

d)

20 30 40 15

17.

Convert the following infix expressions into its equivalent postfix expressions.

(A + B ⋀D)/(E – F)+G

a)

(A B D ⋀ + E F – / G +)

b)

(A B D +⋀ E F – / G +)

c)

(A B D ⋀ + E F/- G +)

d)

(A B D E F + ⋀ / – G +)

18.

The following C function takes a single-linked list of integers as a parameter and rearranges the elements of the list. The function is called with the list containing the integers 1, 2, 3, 4, 5, 6, 7 in the given order. What will be the contents of the list after the function completes execution?

struct node

{

  int value;

  struct node *next;

};

void rearrange(struct node *list)

{

  struct node p, q;

  int temp;

  if ((!list) || !list->next)

      return;

  p = list;

  q = list->next;

  while(q)

  {

     temp = p->value;

     p->value = q->value;

     q->value = temp;

     p = q->next;

     q = p?p->next:0;

  }

}

a)

1,2,3,4,5,6,7

b)

2,1,4,3,6,5,7

c)

1,3,2,5,4,7,6

d)

2,3,4,5,6,7,1

19.

Consider the function f defined below.

struct item

{

  int data;

  struct item * next;

};

 

int f(struct item *p)

{

  return (

          (p == NULL) ||

          (p->next == NULL) ||

          (( P->data <= p->next->data) && f(p->next))

         );

}

a)

not all elements in the list have the same data value

b)

the elements in the list are sorted in non-decreasing order of data value

c)

the elements in the list are sorted in non-increasing order of data value

d)

None of them

20.

Let P be a singly linked list. Let Q be the pointer to an intermediate node x in the list. What is the worst-case time complexity of the best known algorithm to delete the node x from the list?

a)

O(n)

b)

O(log2 n)

c)

O(logn)

d)

O(1)