struct { char c; int i; char d; int j; char e; } s1; |
Assuming the address of the first available memory location is 0xdeadbee0, show the memory locations of each of the variables in s1.
Consider the declaration of variable s2:
struct { int i; int j; char c; char d; char e; } s2; |
Again assuming the address of the first available memory location is 0xdeadbee0, show the memory locations of each of the variables in s2. (Notice that s1 and s2 contain the same variables but in a different order.)
A philatelic society has members whose personal details needs to be computerised. A member has a name, a phone number and an address where an address consists of a house number, a street name and a city. The fields name, street and city are strings; the fields phone and house are integers. Write C data structures to represent this data, preserving the hierarchy in the data.
Given the definitions
int x; int *p; int **q; |
x |
*x |
&x |
p |
*p |
&p |
q |
*q |
&q |
*&x |
for any variable x?
int data[12] = {5, 3, 6, 2, 7, 4, 9, 1, 8}; |
data + 4 |
*data + 4 |
*(data + 4) |
data[4] |
*(data + *(data + 3)) |
data[data[2]] |
typedef struct { char name[20]; int age; char gender; char birthday[10]; } PersonT; PersonT per1; PersonT per2; PersonT *ptr; ptr = &per1; strcpy(per1.name, "Jack"); ptr->gender = 'M'; ptr = &per2; strcpy(ptr->name, "Jill"); ptr->gender = 'F'; per1.age = 20; per2.age = 19; ptr = &per1; strcpy(per2.birthday, "07-06-1990"); strcpy(ptr->birthday, "02-02-1990"); |
What are the values of the fields in the per1 and per2 record after execution of the above statements?