The Debugging Quiz: MCQ Quiz!

Reviewed by Godwin Iheuwa
Godwin Iheuwa, MS, Computer Science |
Computer Expert
Review Board Member
Godwin is a proficient Database Administrator currently employed at MTN Nigeria. He holds as MS in Computer Science from the University of Bedfordshire, where he specialized in Agile Methodologies and Database Administration. He also earned a Bachelor's degree in Computer Science from the University of Port Harcourt. With expertise in SQL Server Integration Services (SSIS) and SQL Server Management Studio, Godwin's knowledge and experience enhance the authority of our quizzes, ensuring accuracy and relevance in the realm of computer science.
, MS, Computer Science
Approved & Edited by ProProfs Editorial Team
The editorial team at ProProfs Quizzes consists of a select group of subject experts, trivia writers, and quiz masters who have authored over 10,000 quizzes taken by more than 100 million users. This team includes our in-house seasoned quiz moderators and subject matter experts. Our editorial experts, spread across the world, are rigorously trained using our comprehensive guidelines to ensure that you receive the highest quality quizzes.
Learn about Our Editorial Process
| By Themes
T
Themes
Community Contributor
Quizzes Created: 410 | Total Attempts: 734,229
Questions: 20 | Attempts: 2,702

SettingsSettingsSettings
The Debugging Quiz: MCQ Quiz! - Quiz

Welcome to our Debugging Quiz, where your coding expertise gets put to the test! Debugging is the method of detecting and fixing bugs inside computer programs, software, or systems. It includes interactive debugging, control flow analysis, unit testing, log file analysis, monitoring of the application, etc. Take this quiz to test your knowledge and learn more about debugging.

In this interactive quiz, you'll encounter a series of coding scenarios riddled with bugs and errors. Your task? To identify these issues, fix them, and ensure that the code runs smoothly.

So, are you ready to embark on this debugging adventure? Take Read moreour Debugging Quiz now and see if you have what it takes to debug like a pro! With each question you answer, you'll gain valuable insights and sharpen your skills, bringing you one step closer to becoming a master debugger. Let's dive in and uncover those elusive bugs together!


Debugging Questions and Answers

  • 1. 

    What is the output of this C code?  #include void main() { int x=1,y=0,z=5; int a=x&&y||z++; printf("%d",z); }

    • A.

      6

    • B.

      5

    • C.

      0

    • D.

      Varies

    Correct Answer
    A. 6
    Explanation
    The output of this C code is 6. This is because the logical AND operator (&&) has higher precedence than the logical OR operator (||). Therefore, the expression "x && y" is evaluated first. Since x is 1 and y is 0, the result of this expression is 0. Then, the logical OR operator is applied to the result of "x && y" and z++. Since the left operand is 0, the right operand (z++) is evaluated. This increments the value of z from 5 to 6. Finally, the result of the logical OR operation is 1, which is assigned to the variable "a". However, the value of "a" is not printed, and instead, the value of z is printed, which is 6.

    Rate this question:

  • 2. 

    What is the output of this C code? #include void main() { int x=1,z=3; int y=x<<3; printf("%d\n",y); }  

    • A.

      -2147483648

    • B.

      Runtime Error

    • C.

      8

    • D.

      -1

    Correct Answer
    C. 8
    Explanation
    The code declares two integer variables, x and z, with values 1 and 3 respectively. It then uses the left shift operator (

    Rate this question:

  • 3. 

    What will be the output? void main() { i=0x10+010+10; printf("\nx=%x",i); }  

    • A.

      I=34

    • B.

      X=22

    • C.

      X=34

    • D.

      Error

    Correct Answer
    B. X=22
    Explanation
    The C code snippet calculates the value of i by summing three numbers expressed in different numeral systems:
    0x10: This is a hexadecimal (base-16) representation which equals 16 in decimal.
    010: This is an octal (base-8) representation which equals 8 in decimal.
    10: This is a decimal representation which is 10.
    Adding these values together: 16+8+10=3416+8+10=34.
    The printf function is then used to output this decimal value (34) as a hexadecimal number:
    %x format specifier in printf converts the decimal number 34 to its hexadecimal equivalent, which is 22.
    Thus, the output printed to the screen will be x=22. This reflects how different numeral systems are interpreted and displayed in C programming.

    Rate this question:

  • 4. 

    Int i=20; Printf(“%X”,i); What is the output?

    • A.

      20

    • B.

      15

    • C.

      14

    • D.

      Error

    Correct Answer
    C. 14
    Explanation
    The code uses the format specifier "%X" in the printf function, which is used to print an integer in hexadecimal format. The variable "i" has a value of 20, which is equivalent to 0x14 in hexadecimal. Therefore, the output of the code will be "14".

    Rate this question:

  • 5. 

    What will be the size of the following union declaration? Union test                        {                                            int x;                                        char y;                                        float z;                                            };                                                 

    • A.

      5

    • B.

      4

    • C.

      6

    • D.

      7

    Correct Answer
    B. 4
    Explanation
    To determine the size of the given union declaration, you need to find the size of the largest member, as the size of a union is determined by the size of its largest member.
    In the provided union declaration:
    int x typically requires 4 bytes (assuming a 32-bit system).
    char y usually requires 1 byte.
    float z typically requires 4 bytes.
    Therefore, the size of the union would be the size of the largest member, which is float z, so the size of the union declaration would be 4 bytes.

    Rate this question:

  • 6. 

    What will be the size of the following union declaration?                          struct test                                              {                                         int x;                                             char y;                                               float z;                                                    };

    • A.

      4

    • B.

      5

    • C.

      6

    • D.

      7

    Correct Answer
    B. 5
    Explanation
    The size of the union declaration will be 5. This is because the union will take the size of the largest member, which in this case is the float z. The size of a float is typically 4 bytes, so the overall size of the union will be 5 bytes (4 bytes for the float z and 1 byte for the char y).

    Rate this question:

  • 7. 

    What will be the output of the following C code? #include int main() { int x = 1, y = 2; int z = x & y == 2; printf("%d\n", z); }

    • A.

      0

    • B.

      1

    • C.

      Error

    • D.

      Depend on compiler

    Correct Answer
    A. 0
    Explanation
    In C, the bitwise AND operator (&) has higher precedence than the equality operator (==). Therefore, the expression x & y == 2 is equivalent to (x & y) == 2.
    Here, x is 1, and y is 2. Performing bitwise AND operation on x and y (1 & 2) gives 0, and then it compares with 2. Since 0 is not equal to 2, the expression (x & y) == 2 evaluates to 0.
    Therefore, the output of the code will be 0.

    Rate this question:

  • 8. 

    The function__________obtains block of memory dynamically.

    • A.

      Calloc

    • B.

      Malloc

    • C.

      Both calloc &malloc

    • D.

      Free

    Correct Answer
    C. Both calloc &malloc
    Explanation
    Both calloc and malloc are functions in C programming language that can be used to dynamically obtain a block of memory. The calloc function is used to allocate and initialize a block of memory with zeros, while the malloc function is used to allocate a block of memory without initializing its contents. Therefore, both calloc and malloc can be used to dynamically allocate memory based on the specific requirements of the program. The free function, on the other hand, is used to deallocate the previously allocated memory.

    Rate this question:

  • 9. 

    What will be the output of the following C code?  #include void main() { int x=0; int *ptr=&x; printf("%d\n",*ptr); }  

    • A.

      Address of x

    • B.

      Zero

    • C.

      Junk value

    • D.

      Runtime Error

    Correct Answer
    B. Zero
    Explanation
    The given C code initializes an integer variable x with the value 0. It then declares a pointer variable ptr and assigns the address of x to it. Finally, it prints the value pointed to by ptr using the printf function. Since ptr points to the variable x, which has a value of 0, the output of the code will be "Zero".

    Rate this question:

  • 10. 

    What will be the output of the C code? #include int main() { int a=1; if(a--)    printf("True");       if(a++)          printf("False"); }

    • A.

      True

    • B.

      False

    • C.

      True False

    • D.

      No output

    Correct Answer
    A. True
    Explanation
    The code starts by initializing the variable a to 1. The first if statement checks if a is true (non-zero), and since a is currently 1, the condition is true and "True" is printed. After that, the value of a is decremented by 1. The second if statement then checks if a is false (zero), but since a is now 0, the condition is false and "False" is not printed. Therefore, the output of the code will be "True".

    Rate this question:

  • 11. 

    For  16-bit compiler allowable range for integer constants is______?

    • A.

      -3.4 e38 to 3.4e38

    • B.

      -32767 to 32768

    • C.

      -32668 to 32667

    • D.

      -32768 to 32767

    Correct Answer
    D. -32768 to 32767
    Explanation
    The correct answer is -32768 to 32767. In a 16-bit compiler, the range for integer constants is determined by the number of bits available for storing the value. In this case, with 16 bits, the range is from -32768 to 32767. This is because the most significant bit is used to represent the sign of the number, allowing for one additional negative value compared to the positive values.

    Rate this question:

  • 12. 

    Python program s='python'print(s*2)print(s*0)print(s*-2)

    • A.

      Error

    • B.

      No Output

    • C.

      Pythonpython

    • D.

      Pythonpythonerror

    Correct Answer
    C. Pythonpython
    Explanation
    The given Python program declares a variable 's' and assigns it the value 'python'. It then prints the value of 's' multiplied by 2, which results in 'pythonpython'. Next, it tries to print the value of 's' multiplied by 0, which would result in an empty string since any number multiplied by 0 is 0. Finally, it tries to print the value of 's' multiplied by -2, which also results in 'pythonpython' since multiplying a string by a negative number simply repeats the string. Therefore, the correct answer is 'pythonpython'.

    Rate this question:

  • 13. 

    Print(max('quiz2code')

    • A.

      122

    • B.

      2

    • C.

      Z

    • D.

      C

    • E.

      Error

    Correct Answer
    C. Z
    Explanation
    The correct answer is "z" because the max() function returns the maximum value in a sequence. In this case, the sequence is the string "quiz2code". The maximum value in this sequence is "z" because "z" comes after all the other characters in the alphabet.

    Rate this question:

  • 14. 

    #include   int main() { int i = 1; if (i++ && (i == 1)) printf("No\n"); else printf("Yes\n"); }

    • A.

      Yes

    • B.

      No

    • C.

      Depends on the  compiler

    • D.

      Depends on the standard

    Correct Answer
    A. Yes
    Explanation
    The given code snippet will output "Yes". This is because the condition in the if statement is evaluating the expression "i++ && (i == 1)". The post-increment operator "i++" will increment the value of i after it is evaluated in the expression. Since i initially has a value of 1, the condition "(i == 1)" will evaluate to true. Therefore, the overall condition will be true and the code inside the if statement will not be executed. Instead, the code inside the else statement will be executed, which prints "Yes".

    Rate this question:

  • 15. 

    What will be  the final value of J in the following C code? #include<stdio> int main() { int i=10,j=0; if(I||(J=I+10))    //DO SOMETING ; }

    • A.

      Zero

    • B.

      Compiler error

    • C.

      20

    • D.

      Depend on language standard

    Correct Answer
    A. Zero
    Explanation
    In the given code, the variable "i" is initialized to 10 and the variable "j" is initialized to 0. Inside the if statement, there is a logical OR operator (||) which checks the truth value of the condition "I" (which should be "i" instead, as "I" is not a valid variable). Since the value of "i" is 10, it is considered as true. Therefore, the second part of the condition, "(J=I+10)" is not evaluated. Hence, the value of "j" remains 0, resulting in the final value of "j" being zero.

    Rate this question:

  • 16. 

    Waht will be the output of the following C code? #include <stdio.h> int main() { int a=2,b=0; int y=(b==0)?a:(a>b)?(b=1):a; printf("%d",y); }

    • A.

      Compile time error

    • B.

      One

    • C.

      Two

    • D.

      Undefined behavior

    Correct Answer
    C. Two
    Explanation
    The code will output "two".

    The code first checks if b is equal to 0. Since it is not, it moves on to the next condition. The condition (a>b) is true since a is 2 and b is 0. Therefore, the code assigns the value 1 to b. The value of y is then assigned as the value of a, which is 2. Finally, the code prints the value of y, which is 2.

    Rate this question:

  • 17. 

    What will be the output of the following C code? #include <stdio.h> int main() {     if(7&8) printf("Honest");     if((~7&0*000f)==8) printf("is the best policy"); }

    • A.

      Honest is the best policy

    • B.

      Honest

    • C.

      Is the best policy

    • D.

      No output

    Correct Answer
    B. Honest
    Explanation
    The first if statement checks the condition 7 & 8. In this condition, the bitwise AND operation (&) is applied to the numbers 7 and 8. The result is 0 because the binary representation of 7 is 0111, and the binary representation of 8 is 1000. When you perform a bitwise AND operation, you get 0 because there are no common set bits. So, the first if condition is false, and "Honest" is not printed.
    The second if statement checks the condition (~7 & 0*000f) == 8. Here, ~7 represents the bitwise NOT of 7, which is -8 in two's complement representation. 0*000f is simply 0. When you apply the bitwise AND operation to -8 and 0, you get 0. Finally, the condition 0 == 8 is false, so "is the best policy" is not printed.
    Therefore, only "Honest" is printed as the output.

    Rate this question:

  • 18. 

    What will the output of the following C code be? #include int main() { int k=8; int m=7; k

    • A.

      Runtime error

    • B.

      Compiletime error

    • C.

      7

    • D.

      8

    Correct Answer
    B. Compiletime error
    Explanation
    The given code will result in a compile-time error. This is because the code is incomplete and there is a syntax error in the line "k
    ". The less than symbol should be followed by a value or a variable to compare with. Since it is incomplete, the compiler will throw an error and the code will not compile successfully.

    Rate this question:

  • 19. 

    Waht will be the output of this? #include int main() { int a[]={2,3}; int b[]={4,6}; if(a) { int a=7; int b=8; printf("%d",a); } }

    • A.

      7

    • B.

      3

    • C.

      8

    • D.

      6

    • E.

      Error

    Correct Answer
    A. 7
    Explanation
    In this code, the variable "a" is declared twice - once as an array and once as an integer within the if statement. Inside the if statement, a new local variable "a" is declared and assigned the value 7. Therefore, when the printf statement is executed, it will print the value of the local variable "a" which is 7.

    Rate this question:

  • 20. 

    What will be the output of the following c code? int main() {   int x=-2;   x=x>>1; printf("%d\n",x); }

    • A.

      1

    • B.

      -1

    • C.

      231-1 considering int to be 4 bytes

    • D.

      2

    Correct Answer
    B. -1
    Explanation
    The given C code initializes the variable x with the value -2. Then, it performs a right shift operation on x by 1 bit. This operation shifts all the bits of x to the right by 1 position. Since the variable x is a signed integer, the right shift operation preserves the sign bit. In this case, the sign bit is 1 because x is negative. Therefore, the output of the code will be -1.

    Rate this question:

Godwin Iheuwa |MS, Computer Science |
Computer Expert
Godwin is a proficient Database Administrator currently employed at MTN Nigeria. He holds as MS in Computer Science from the University of Bedfordshire, where he specialized in Agile Methodologies and Database Administration. He also earned a Bachelor's degree in Computer Science from the University of Port Harcourt. With expertise in SQL Server Integration Services (SSIS) and SQL Server Management Studio, Godwin's knowledge and experience enhance the authority of our quizzes, ensuring accuracy and relevance in the realm of computer science.

Quiz Review Timeline +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Apr 15, 2024
    Quiz Edited by
    ProProfs Editorial Team

    Expert Reviewed by
    Godwin Iheuwa
  • Mar 10, 2021
    Quiz Created by
    Themes
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.