Logic Building Quiz for DSA

Last Updated :
Discuss
Comments

Question 1

What will be the value of x after the following code executes?

x = 5;  
if (x > 3)
{ x = x + 2; }
else
{ x = x - 2; }
  • A

    7

  • B

    3

  • C

    5

  • D

    1

Question 2

Given the following pseudo code, what will be the output?

x = 4; 
if (x > 5)
{ print("Greater") }
else if ( x<2 )
{ print("Lesser") }
else
{ print( " None") }
  • A

    Lesser

  • B

    Greater

  • C

    None of the above.

  • D

    None

Question 3

What will be the output of this switch-case pseudo code?

x = 4;
switch(x)
{ case 3:
print("One");
break;
case 9:
print("Two");
break;
case 4:
print("Three");
break;
default:
print("Other");
}
  • A

    One

  • B

    Two

  • C

    Three

  • D

    Other

Question 4

How many times will the following while loop print "Hello"?

x = 5;
while(x > 1) {
print("Hello");
x = x - 1;
}


  • A

    1

  • B

    4

  • C

    6

  • D

    5

Question 5

Which of the following is the correct way to check if a variable x is not equal to 10 in languages like C/C++, Java and Python.

  • A

    if(x != 10)

  • B

    if(x ==! 10)

  • C

    if(x <> 10)

  • D

    if(x =! 10)

Question 6

What will be the value of x after executing the following pseudo codes

a)
x = 9;
x == 8;
b)
x = 9;
x = 7;


  • A

    8, 9

  • B

    8, 7

  • C

    9 , 7

  • D

    9, 9

Question 7

If an array has n elements then what will be the index of the last element of the array?

  • A

    0

  • B

    n

  • C

    n + 1

  • D

    n - 1

Question 8

What is the result of the following expression?

Here && is logical AND operator

( 5 < 8 ) && ( 3 > 1 ) 
  • A

    True

  • B

    False

  • C

    None of the above

  • D

    Undefioned

Question 9

What will be the value of z after the following code?

x = 4;
y = 3;
z = x * y + 2;


  • A

    10

  • B

    14

  • C

    12

  • D

    9

Question 10

What will be the output of the following code?
( Where, || is a logical operator )

x = 5;
y = 10;

if(x > 3 || y < 5) {
print("Condition True");
} else {
print("Condition False");
}


  • A

    Condition False

  • B

    Condition True

  • C

    Nothing

  • D

    Error

Tags:

There are 15 questions to complete.

Take a part in the ongoing discussion