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: 93
| Attempts: 93
SettingsSettings
Please wait...
  • 1/20 Questions

    Main() { int a=3; int *b=a; printf(“%d”,b); }

Please wait...
About This 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.

Coding And Debugging - Round 1- Set B - Quiz

Quiz Preview

  • 2. 

    Int main() { int n; printf("Enter a number:\n"); scanf("%d\n",n); printf("You entered %d \n",n); return 0; }

  • 3. 

    Main() { int n; scanf("%d",&n); printf("%c",n); }

  • 4. 

    Main() { printf("!hello World); }

  • 5. 

    #include int main() { printf("Value of a : %d",a); return 0; }

  • 6. 

    Int Main() { printf("Hello : "); return 0; }

  • 7. 

    Int Main() { printf("Hello : "); return 0; }

  • 8. 

    Main() { int a=3; int b=2; int c=a

  • 9. 

    Void main() { int a=4; printf(“%d”,a); return 0; }

  • 10. 

    Main() { int a=10; printf(“%d”a); }

  • 11. 

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

    • Equal

    • Not equal

    • Depend on compiler

    • None of the above

    Correct Answer
    A. 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;}

    • P and q are 4 and 4

    • p and q are 4 and 8

    • Compiler error

    • P and q are 2 and 8

    Correct Answer
    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

    • Run time error

    • A.0000000

    • 97.000000

    Correct Answer
    A. 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"); }

    • Hi

    • How are you

    • Hello

    • Hihello

    Correct Answer
    A. 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"); } }

    • 1

    • Hi 2

    • Run time error

    • 2

    Correct Answer
    A. 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"); } }

    • H

    • H is printed infinte times

    • Compile time error

    • Varies

    Correct Answer
    A. 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); }

    • 5

    • 10

    • 7

    • 1

    Correct Answer
    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"); } }

    • Hi is printed 5 times

    • Hi is printed 9 times

    • Hi is printed 7 times

    • Hi is printed 4 times

    Correct Answer
    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; } } }

    • Loop loop

    • Compilation error

    • Loop loop loop loop

    • Infinte loop

    Correct Answer
    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"); } } }

    • Hi is printed 9 times

    • Hi is printed 8 times

    • Hi is printed 7 times

    • Hi is printed 6 times

    Correct Answer
    A. Hi is printed 8 times
    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.

    Rate this question:

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
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.