typedef struct FloatBits FloatBits;
struct FloatBits {
unsigned int significand : 23;
unsigned int exponent : 8;
unsigned int sign : 1;
};
typedef union FloatIntBits FloatIntBits;
union FloatIntBits {
float the_float;
int the_int;
FloatBits the_bits;
};
int main(int argc, char** argv) {
if (argc < 2) {
printf("Give me a float!");
return 0;
}
FloatIntBits fib = {.the_float = atof(argv[1])};
printf("The size of fib is %lu\n", sizeof(fib));
printf("The size of FloatBits is %lu\n", sizeof(FloatBits));
printf("The sign is %u, the exponent is %u, and the significand is %u\n", fib.the_bits.sign, fib.the_bits.exponent, fib.the_bits.significand);
printf("%f as an int is %i\n", fib.the_float, fib.the_int);
return 0;
}
```
---
## Review
* We'll have one more lecture before the quiz
* On data representation and arithmetic before the quiz
* Won't be on the quiz though
* Material will cover through today's lecture
* Let's review with a few example questions
---
## Q1
What is the output of the following code snippet?
printf("6 / 4 = %i\n", 6/4);
a. 1
b. 1.5
c. 1.0
d. This code is not syntactically correct and will not compile.
---
## Q2
The exit status of a program is NOT:
a. Always an integer.
b. Generally nonzero to indicate failure.
c. The value of the last variable cleaned up from the stack.
d. The value returned from the main function.
---
## Q3
After the following line of code, what is the value of a?
int a = 2.7;
a. 2.7
b. 2
c. The value will be architecture specific.
d. This code is not syntactically correct and will not compile.
---
## Q4
On a 64-bit machine, the maximum value of a signed long long int will be
a. $2^{32}$
b. INT_MAX as defined in limits.h
c. $2^{63}$ - 1
d. $2^{64}$ - 1
---
## Q5
Which of the following statements about argc and argv are false?
a. The values of argc and argv are only known at run time.
b. C requires both argc and argv when declaring the main function.
c. argv is a pointer that ponits to other pointers.
d. argc[0] is the program name itself.
---
## Q6
```
#include
int main(int argc, char** argv) {
printf("%lu\n", sizeof(int*));
return 0;
}
```
The above code will:
a. Print the size of a pointer on the current architecture.
b. Print the size of an int on the current architecture.
c. It will not compile because sizeof cannot be used with int*.
d. It will not compile for other reasons.
---
## Q7
int a = 6;
int *b = &a;
b[0] = 2;
*b += 10;
After the above, code, what is the value of a?
a. 6
b. 12
c. 16
d. None of those.
---
## Q8
In a little endian system, the first byte of an integer is
a. Loaded into a register first during qword instructions
b. Where the sign bit is stored
c. The least significant
d. The most significant
---
## Q9
The type signature for the calloc function is as follows:
void *calloc(size_t nmemb, size_t size);
Write a single line of code that declares an int* and sets it equal to dynamically allocated memory with space for 35 integers.
\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_