# Coding And Debugging - Round 1- Set B

Approved & Edited by ProProfs Editorial Team
At ProProfs Quizzes, our dedicated in-house team of experts takes pride in their work. With a sharp eye for detail, they meticulously review each quiz. This ensures that every quiz, taken by over 100 million users, meets our standards of accuracy, clarity, and engagement.
| Written by Salvationz2k16
S
Salvationz2k16
Community Contributor
Quizzes Created: 1 | Total Attempts: 48
Questions: 20 | Attempts: 48  Settings  • 1.

• 2.

• 3.

• 4.

• 5.

• 6.

• 7.

• 8.

• 9.

• 10.

• 11.

### #include int main() { float f1 = 0.1; if (f1 == 0.1) printf("equal\n"); else printf("not equal\n"); }

• A.

Equal

• B.

Not equal

• C.

Depend on compiler

• D.

None of the above

B. Not equal
Explanation
The reason why the answer is "not equal" is because floating-point numbers cannot be represented exactly in binary. The value 0.1 cannot be represented exactly in binary, so when it is assigned to the variable f1, it may not have the exact value of 0.1. Therefore, when comparing f1 to 0.1, they may not be equal.

Rate this question:

• 12.

### #include int main(){int x = 10000;double y = 56;int *p = &x;double *q = &y;printf("p and q are %d and %d", sizeof(p), sizeof(q));return 0;}

• A.

P and q are 4 and 4

• B.

p and q are 4 and 8

• C.

Compiler error

• D.

P and q are 2 and 8

A. P and q are 4 and 4
Explanation
The correct answer is "p and q are 4 and 4". The sizeof() function in C returns the size in bytes of its operand. In this case, p is a pointer to an integer and q is a pointer to a double. Both of these pointer types have a size of 4 bytes on most systems. Therefore, the sizeof(p) and sizeof(q) both evaluate to 4.

Rate this question:

• 13.

### #include int main() { float x = 'a'; printf("%f", x); return 0; } #include int main() { float x = 'a'; printf("%f", x); return 0; }

• A.

a

• B.

Run time error

• C.

A.0000000

• D.

97.000000

D. 97.000000
Explanation
The correct answer is 97.000000 because in the code, the variable "x" is assigned the value of 'a', which is the ASCII value of the character 'a'. Since "x" is a float data type, it will be implicitly converted to its corresponding ASCII value, which is 97. When the printf function is called with the format specifier "%f", it will print the value of "x" as a floating-point number, which is 97.000000.

Rate this question:

• 14.

### #include void main() { int x = 0; if (x == 0) printf("hi"); else printf("how are u"); printf("hello"); }

• A.

Hi

• B.

How are you

• C.

Hello

• D.

Hihello

D. Hihello
Explanation
The given code snippet is a C program that prints "hi", "how are u", and "hello" on separate lines. The variable x is initialized to 0 and the if statement checks if x is equal to 0. Since x is indeed equal to 0, the code inside the if block is executed, which prints "hi". The code outside the if block, which is the printf statement for "hello", is always executed regardless of the if condition. Therefore, the output of the program is "hi" followed by "hello".

Rate this question:

• 15.

### #include void main() { int ch; printf("enter a value btw 1 to 2:"); scanf("%d", &ch); switch (ch) { case 1: printf("1\n"); break; printf("Hi"); default: printf("2\n"); } }

• A.

1

• B.

Hi 2

• C.

Run time error

• D.

2

D. 2
Explanation
The given code snippet is using a switch statement to check the value of the variable "ch". If the value is 1, it will print "1". However, after the break statement, there is a printf statement that will print "Hi". This statement is unreachable because the break statement will cause the control to exit the switch statement. Therefore, the code will only print "1".

Rate this question:

• 16.

### #include void main() { int i = 0; while (++i) { printf("H"); } }

• A.

H

• B.

H is printed infinte times

• C.

Compile time error

• D.

Varies

B. H is printed infinte times
Explanation
The given code is an infinite loop because the condition of the while loop is always true. The variable "i" is incremented by 1 before each iteration of the loop. Since the value of "i" is initially 0, it becomes 1 in the first iteration, which satisfies the condition of the while loop. Therefore, the statement "H" is printed infinitely.

Rate this question:

• 17.

### #include int main() { int a = 0, i = 0, b; for (i = 0;i < 5; i++) { a++; continue; printf("%d",a); } printf("%d",a); }

• A.

5

• B.

10

• C.

7

• D.

1

A. 5
Explanation
In this code, a variable 'a' is initialized to 0. Then, a for loop is executed 5 times. In each iteration, the value of 'a' is incremented by 1 using the 'a++' statement. The 'continue' statement is used to skip the remaining code inside the loop and move to the next iteration. Therefore, the printf statement inside the loop is never executed. After the loop, the final value of 'a' is printed, which is 5.

Rate this question:

• 18.

### #include void main() { int i = 0, j = 0; for (i = 0;i < 5; i++) { for (j = 0;j < 4; j++) { if (i > 1) break; } printf("Hi \n"); } }

• A.

Hi is printed 5 times

• B.

Hi is printed 9 times

• C.

Hi is printed 7 times

• D.

Hi is printed 4 times

A. Hi is printed 5 times
Explanation
The inner loop is never executed because the condition "i > 1" is never true. Therefore, the inner loop doesn't affect the number of times "Hi" is printed. The outer loop runs 5 times, so "Hi" is printed 5 times.

Rate this question:

• 19.

### #include int main() { int i = 0, j = 0; l1: while (i < 2) { i++; while (j < 3) { printf("loop\n"); goto l1; } } }

• A.

Loop loop

• B.

Compilation error

• C.

Loop loop loop loop

• D.

Infinte loop

A. Loop loop
Explanation
The code starts with initializing the variables i and j to 0. Then it enters a while loop with the condition i < 2. Inside this while loop, i is incremented by 1. Then it enters another while loop with the condition j < 3. Inside this while loop, "loop" is printed and then a goto statement is used to jump back to the label l1. This causes the code to repeat the previous while loop. Since j is never incremented, it remains 0 and the second while loop keeps getting executed infinitely. Therefore, the output will be "loop loop" repeatedly.

Rate this question:

• 20.

### #include void main() { int i = 0; int j = 0; for (i = 0;i < 5; i++) { for (j = 0;j < 4; j++) { if (i > 1) continue; printf("Hi \n"); } } }

• A.

Hi is printed 9 times

• B.

Hi is printed 8 times

• C.

Hi is printed 7 times

• D.

Hi is printed 6 times Back to top