homework6

# homework6 - Answer : 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15...

This preview shows pages 1–2. Sign up to view the full content.

Homework 6 Problem 1: Given a structure named “ Node , and “ Next is a field of the Node structure. Like this: If there is an object of Node named MyNode and the address of the Next field is known. Can you given a C expression which can calculate the address of MyNode ? ( NOTE: you can just use the address of the Next field . Next ) ) Problem 2: Consider the following C declaration: Using the templates below (allowing a maximum of 28 bytes), indicate the allocation of data for structs of type data_t . Mark off and label the areas for each individual element. Cross hatch the parts that are allocated, but not used, and be sure to clearly indicate the end of the structure. Assume the Linux alignment rules discussed in class.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Answer : 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 Struct Node{ ... Struct Node *Next; ... }; typedef struct data_s { short start; double len; double *real_data; short end; struct data_s *next; } data_t; Problem 3: Please answer the following questions, assuming sizeof(int)=4, sizeof(long)=4: A. Given a piece of C code: What’s the value of variable n? Answer : B. Given a piece of C code: What result will be printed out? Answer : int a[20]; char * p1 = (char *)a; char * p2 = (char *)(a+5); int n= p2 ‐ p1; char * p = “ helloics ” , *r; long *q; q=(long* )p; q++; r=(char *)q; printf("%s\n", r);...
View Full Document

## This note was uploaded on 10/19/2011 for the course CS 000 taught by Professor Jing during the Fall '10 term at Fudan University.

### Page1 / 2

homework6 - Answer : 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online