logo

Crowdly

Attempt either (A) or (B). Write down clearly in your answer which one you are...

✅ Перевірена відповідь на це питання доступна нижче. Наші рішення, перевірені спільнотою, допомагають краще зрозуміти матеріал.

Attempt either (A) or (B). Write down clearly in your answer which one you are attempting.

A.
In the following piece of code intended to receive user input character by character, and display it on the screen, the programmer did not pay attention to a subtle detail, due to which the program does not work as expected (even though it does not throw any compilation errors):

while (ch = getchar() != EOF)

  putchar(ch);

Can you help the programmer fix the bug by rewriting the code? Explain briefly.

(OR) 
B.

The following code segment written by a beginner in C does not work as expected. However, there is no compilation error. Can you spot the bug and rewrite the piece of code so it is bug-free? Explain briefly why the bug arose.

int

x = 5;

if (x = 0)

    printf("Zero\n");

else

    printf("Non-zero\n

");

Більше питань подібних до цього

Хочете миттєвий доступ до всіх перевірених відповідей на dle.plaksha.edu.in?

Отримайте необмежений доступ до відповідей на екзаменаційні питання - встановіть розширення Crowdly зараз!