Coding And Debugging - Round 1- Set B

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 Salvationz2k16
S
Salvationz2k16
Community Contributor
Quizzes Created: 1 | Total Attempts: 64
Questions: 20 | Attempts: 64

SettingsSettingsSettings
Coding And Debugging - Round 1- Set B - Quiz


Questions and Answers
  • 1. 

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

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

    • A.

      Equal

    • B.

      Not equal

    • C.

      Depend on compiler

    • D.

      None of the above

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

    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.

      a

    • B.

      Run time error

    • C.

      A.0000000

    • D.

      97.000000

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

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

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

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

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

    • A.

      Hi is printed 5 times

    • B.

      Hi is printed 9 times

    • C.

      Hi is printed 7 times

    • D.

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

    • A.

      Loop loop

    • B.

      Compilation error

    • C.

      Loop loop loop loop

    • D.

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

    • A.

      Hi is printed 9 times

    • B.

      Hi is printed 8 times

    • C.

      Hi is printed 7 times

    • D.

      Hi is printed 6 times

    Correct Answer
    B. 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 +

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.