Provide the following screen shots a A screen shot of your completed source

Provide the following screen shots a a screen shot of

This preview shows page 5 - 9 out of 11 pages.

Provide the following screen shots a) A screen shot of your completed source code within a Linux text editor (5pts) b) A screen shot that shows i) the gcc command to compile your program, ii) the command to run your program, iii) the output of your program. (5pts)
Image of page 5
Name : Lab Section: Question 6: Struct and Union (10 pts) (Graded)* What is the size of the following data structures in bytes. a) Size of point3D 9 (2 pts) struct point3D { signed long x; // 4 unsigned int y; // 4 char z; // 1 }; b) Size of val 32 (2 pts) union val { char cval; // 1 char str; // 1 int ival[8]; // 4*8 = 32 float fval; // 4 double dval; // 8 }; c) Size of compound 12 (3 pts) struct compound { char *mystring; // 4 long y; // 4 union { char *c; // 4 int *i; // 4 float *f; // 4 } u; }; d) Size of more_compound 22 (3 pts) struct more_compound { char *name; // 4 int age; // 4 short pay; // 2 long *height; // 4 union { char short_id; // 1 int normal_id; // 4 char my_id; // 1 } id; union { char *text_data; // 4 int *numeric_data; // 4 long l_numeric_data; // 4 } data; };
Image of page 6
Name : Lab Section: Question 7: Pointers (10 pt) (Not Graded) What is the value of a , b, c_ptr at the end of each program. Give N/A if a value is undefined. It is recommended that you practices drawing a memory map for solving these questions. Assume the following memory locations for the variables: - Location of a is 0xFFFF_FF00 - Location of b is 0xFFFF_FE00 - Location of c_ptr is 0xFFFF_FD00 a. 3pts void main() { char a = 5; char b = 10; char *c_ptr; c_ptr = &a; // c_ptr = 0xFFFF_FF00 *c_ptr = 12; //Go to 0xFFFF_FF00 and set to 12, i.e. sets a=12 *c_ptr = b;//Go to 0xFFFF_FF00 and set to b, i.e. sets a=b==10 c_ptr = &b; // c_ptr = 0xFFFF_FE00 *c_ptr = a;// Go to 0xFFFF_FE00 and set to a, i.e. sets b=a==10 } a is 10 b is 10 c_ptr is 0xFFFF_FE00 . b. 3pts void main() { char a = 5; char b = 10; char *c_ptr = 0; c_ptr = &a; // c_ptr = 0xFFFF_FF00 c_ptr = &b; // c_ptr = 0xFFFF_FE00 (*c_ptr)++; //Go to 0xFFFF_FE00 and increase by 1, i.e. b++==11 c_ptr++; // c_ptr = c_ptr + (1 * 1) == 0xFFFF_FE01 } a is 5 b is 11 c_ptr is 0xFFFF_FE01 .
Image of page 7
Name : Lab Section: c. 4pts (note all variables were changed from chars to ints or pointers to ints). void main() { int a = 5; int b = 10; int *c_ptr = 0; c_ptr = &b; // c_ptr = 0xFFFF_FE00 a = *c_ptr + b; // Go to 0xFFFF_FE00 and get value. Then add // value with b, and store the result in a, // i.e. a = b + b == 20 (*c_ptr)++;// Go to 0xFFFF_FE00 and increase by 1, i.e. b++==11 c_ptr++; // c_ptr = c_ptr + (1 * 4) = 0xFFFF_FE04 } a is 20 b is 11 c_ptr is 0xFFFF_FF04 .
Image of page 8
Image of page 9

You've reached the end of your free preview.

Want to read all 11 pages?

  • Fall '09
  • Lab section, char msg, c_ptr, char cval

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture