# The Debugging Quiz: MCQ Quiz!

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.
| By Themes
T
Themes
Community Contributor
Quizzes Created: 424 | Total Attempts: 637,152
Questions: 20 | Attempts: 1,881  Settings  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.

• 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

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

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

B. X=22
Explanation
In this code, the variable i is assigned the value of 0x10 (which is 16 in hexadecimal), 010 (which is 8 in octal), and 10 (which is 10 in decimal). When these values are added together, the result is 34. The printf statement then uses the format specifier %x to print the value of i in hexadecimal format. So the output will be x=22.

Rate this question:

• 4.

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

• A.

20

• B.

15

• C.

14

• D.

Error

C. 14
Explanation
The code is using 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

A. 5
Explanation
The size of the union declaration will be 5. This is because the size of a union is determined by the size of its largest member, which in this case is an int (4 bytes). However, unions also typically have padding added to align their members, and in this case, the padding adds an additional byte to the size, resulting in a total size of 5 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

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

B. 1
Explanation
The code declares three variables: x, y, and z. It then assigns the values 1 and 2 to x and y, respectively. The expression "x & y == 2" is evaluated, which performs a bitwise AND operation between x and y, resulting in 0. However, the expression also includes the equality comparison "== 2", which has higher precedence than the bitwise AND operator. Since the result of the bitwise AND operation is not equal to 2, the expression evaluates to false, which is represented by the value 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

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.

• B.

Zero

• C.

Junk value

• D.

Runtime Error

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

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

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

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

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

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

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

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

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 be the output of following C code? #include int main() { int k=8; int m=7; k

• A.

Runtime error

• B.

Compiletime error

• C.

7

• D.

8

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

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

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:

Related Topics Back to top