SpaceDog SpaceDog - 1 year ago 68
C Question

Why write 1,000,000,000 as 1000*1000*1000 in C?

In code created by Apple, there is this line:

CMTimeMakeWithSeconds( newDurationSeconds, 1000*1000*1000 )

Is there any reason to express

Why not
for that matter?

Answer Source

One reason to declare constants in multiplicative way, is to improve readability, while the run-time performance is not affected. Also, to indicate, that the writer was thinking in multiplicative manner about the number. Consider this:

double memoryBytes = 1024 * 1024 * 1024;

It's clearly better, than

double memoryBytes = 1073741824;

as the later is not at first glance the third power of 1024.

As Amin Negm-Awad mentioned, the '^' operator is the binary XOR. many languages lack the build - in, compile time exponentiation operator, hence the multiplication.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download