Question: C problems: 1: Consider the problem of padding the following structure, and answer the questions below. Assume that you are compiling on a system with
C problems:
1:
Consider the problem of padding the following structure, and answer the questions below. Assume that you are compiling on a system with a 32-bit architecture.
struct BMP_Header {
char signature[2];
int size;
char reserved1;
enum offset_type offset_pixels;
};
a) What is the size of this struct as defined?
b) How much space would be wasted with word length padding?
2:
Consider the following fragment of code which is meant to add two together two xy points, and answer the two questions below:
struct point {
int x;
int y
};
struct point* add_points(struct point* p1, struct point* p2) {
struct point result;
result.x = p1->x + p2->x;
result.y = p1->y + p2->y;
return &result;
}
Most of the time function will appear to work fine, but then later there will be an issue with the result point's data changing unexpectly.
a) What is the problem?
b) How it can be fixed?
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
