C
Chad
The question is related to the following lines of code:
#include <stdio.h>
#include <math.h>
int main(void) {
int a = (int)pow(2.0 ,32.0);
double b = pow(2.0 , 32.0);
printf("The value of a is: %u\n",a);
printf("The value of b is: %0.0f\n",b);
printf("The value of int is: %d\n", sizeof(int));
printf("The value of double is: %d\n", sizeof(double));
return 0;
}
The output is:
$./pw
The value of a is: 2147483648
The value of b is: 4294967296
The value of int is: 4
The value of double is: 8
The value of 'a' (on my machine) is 2147483648 or 2^31. Is this anyway
related to the fact that 1 int in this case is 32 bits? I
Thanks in advance.
Chad
#include <stdio.h>
#include <math.h>
int main(void) {
int a = (int)pow(2.0 ,32.0);
double b = pow(2.0 , 32.0);
printf("The value of a is: %u\n",a);
printf("The value of b is: %0.0f\n",b);
printf("The value of int is: %d\n", sizeof(int));
printf("The value of double is: %d\n", sizeof(double));
return 0;
}
The output is:
$./pw
The value of a is: 2147483648
The value of b is: 4294967296
The value of int is: 4
The value of double is: 8
The value of 'a' (on my machine) is 2147483648 or 2^31. Is this anyway
related to the fact that 1 int in this case is 32 bits? I
Thanks in advance.
Chad