Need help analyzing this C program?

I don’t understand why while(status == ) works in this program, and why it doesn’t work if I have while(status == )? Thank You,

#include <stdio.h>

int main(void)


int num;

int sum = ;

int status;

printf(“Please enter an integer to be summed”);

printf(“(q to quit):”);

status = scanf(“%d”, &num);

while(status == )


sum = sum + num;

printf(“Please enter next integer(q to quit):”);

status = scanf(“%d”, &num);


printf(“Those integers sum to %d.n”, sum);

return ;


✅ Answers

? Favorite Answer

  • scanf() returns the number of items that it could convert. Since you have “%d” that is a single conversion. So, scanf() will return or . If you had “%d %d”, that would be two conversions, and scanf would return , or (depending on what it could convert).

    I don’t know where you got from – q is not a number, so scanf() can’t convert, and returns .

    Also, scanf() can return EOF (- typically) if end of input is reached before the first successful conversion (or matching failure). EOF is also returned on a read error. If a negative return from scanf() is seen, you can look at the errno variable for more details on the error (interrupted, out of memory, range, etc.).

  • Ah, I think you misunderstand how scanf works. Scanf will take the number given and store it into the address you give it (in your case, the num variable). It then returns if it succeeded or (I’m guessing) if it fails.

    Having while status== will never occur, since scanf won’t return .

  • The on an analogous time as loop above converts a binary huge type (base ) represented as a string of s and s right into a decimal (base ) fee. As for something? it is not being “declared” , the logo % is the C operator for modulo. In computing, the modulo (frequently pronounced as modulus) operation unearths something of branch of one huge type by skill of yet another. Given helpful numbers, a (the dividend) and n (the divisor), a modulo n (abbreviated as a mod n) is something of the Euclidean branch of a by skill of n. working example, the expression ” mod ” could evaluate to a million because of the fact divided by skill of two leaves a quotient of two and a the remainder of a million. In environments without modulus operator the equivalent calculation could be; a – (n * int(a/n)) So on your code above; the line “the rest=binaryNumberp.c.;” could be examine; the rest is-equivalent-to the fee of the identifier “binaryNumber” mod

  • that is because scanf() returns the number of successful conversions.…

    so in your case scanf will return or or EOF

    it will never return since you are asking only for one item to be entered.


  • Leave a Comment