Coding And Debugging - Round 1- Set B

Reviewed by Editorial Team
The ProProfs editorial team is comprised of experienced subject matter experts. They've collectively created over 10,000 quizzes and lessons, serving over 100 million users. Our team includes in-house content moderators and subject matter experts, as well as a global network of rigorously trained contributors. All adhere to our comprehensive editorial guidelines, ensuring the delivery of high-quality content.
Learn about Our Editorial Process
| By Salvationz2k16
S
Salvationz2k16
Community Contributor
Quizzes Created: 1 | Total Attempts: 107
| Attempts: 107 | Questions: 10
Please wait...
Question 1 / 10
0 %
0/100
Score 0/100
1. #include void main() { int i = 0; while (++i) { printf("H"); } }

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.

Submit
Please wait...
About This Quiz
Coding And Debugging - Round 1- Set B - Quiz

This 'Coding and Debugging - Round 1- Set B' quiz assesses key software development skills, focusing on understanding C\/C++ language specifics, such as data types, memory management, and control structures. It challenges learners to identify and correct common coding pitfalls, enhancing their debugging capabilities.

Personalize your quiz and earn a certificate with your name on it!
2. #include int main() { int i = 0, j = 0; l1: while (i < 2) { i++; while (j < 3) { printf("loop\n"); goto l1; } } }

Explanation

The code starts with initializing the variables i and j to 0. Then it enters a while loop with the condition i

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

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.

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

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".

Submit
5. #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"); } }

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.

Submit
6. #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"); } } }

Explanation

The code contains nested for loops. The outer loop runs 5 times and the inner loop runs 4 times. However, there is a conditional statement inside the inner loop that uses the "continue" keyword. This means that if the value of "i" is greater than 1, the inner loop will skip the rest of its iterations and move to the next iteration of the outer loop. Therefore, when "i" is 2, 3, or 4, the inner loop is skipped entirely. As a result, "Hi" is only printed during the first two iterations of the outer loop, which gives a total of 8 times.

Submit
7. #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;}

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.

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

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.

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

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.

Submit
10. #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"); } }

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".

Submit
View My Results

Quiz Review Timeline (Updated): Apr 20, 2023 +

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

  • Current Version
  • Apr 20, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Sep 21, 2016
    Quiz Created by
    Salvationz2k16
Cancel
  • All
    All (10)
  • Unanswered
    Unanswered ()
  • Answered
    Answered ()
#include ...
#include ...
#include ...
#include ...
#include ...
#include ...
#include int main(){int x = 10000;double y = 56;int *p = &x;double...
#include ...
#include ...
#include ...
Alert!

Advertisement