O'Reilly logo

C Primer Plus, Fourth Edition by Stephen Prata

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 6

1: Find the value of quack after each line.
int quack = 2;
quack += 5;
quack *= 10;
quack -= 6;
quack /= 8;
quack %= 3;
A1: 2, 7, 70, 64, 8, 2
2: Given that value is an int, what output would the following loop produce?
for ( value = 36; value > 0; value /= 2)
      printf("%3d", value);

What problems would there be if value were double instead of int?

A2: It would produce the following output:
36 18  9  4  2  1

If value were double, the test would remain true even when value became less than 1. The loop would continue until floating-point underflow yielded a value of 0. Also, the %3d specifier would be the wrong choice.

3: Represent each of the following test conditions:
  1. x is greater than 5.

  2. scanf() attempts to read a single double (called x) and ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required