jacqueliug28midtermcat n problem1c include include define SI

jacqueli@ug28:-/midterm>cat -n problem1.c #include #include #define SIZE 64 char buffer [SIZE]; int main (int argc, char *argv (]) (char * cat_name = \"Mittens\"; char * pet_name; strncpy (buffer, cat_name, SIZE-1);/* buffer is the destination */print f (\" cat_name = %p/%1d\ \", cat_name, (long) cat_name); return (0);/* end of main */jacqueli@ug28: -/midterm>gcc -std=c99 problem1.c -o problem1 jacqueli@ug28: -/midterm> ./problem1 cat_name = 0x4006cc/4196044 &buffer; [0] = 0x601060/6295648 buffer = 0x601060/6295648 When answering the following questions, use the proper and relevant C and UNIX terminology. For numerical answers, you may use either hexadecimal or decimal numbers. As of line 12 of the program, what is the address of the storage for variable buffer? What is the address of the first byte of the string constant \"Mittens \"? As of line 18 of the program, what is the value of the address expression & (pet_name [2]) ? On line 15 of the program, which segment of memory is being accessed (i.e., loaded from) on the right-hand-side of the assignment (i.e., \"=\"). As of line 17 of the program, what ASCII character is at buffer [3] ?

Solution


1.
   Address of \'buffer\' is the same as address of \'buffer[0]\', because address name represent first element of array

   Ans: 0x601060

2.
   Address of first byte of address of \'Mittens\' is same as
   address of \'cat_name\' because \'cat_name\' is the address of first
   element of \'Mittens\'

   Ans: 4196044

3.
   Address of (pet_name[2]) is the address of third element
   of \'pet_name\'
   Ans: address_of_first_byte_of_pet_name + 2
   = 4196044 + 2= 4196046 (I am assuming char takes 1 byte)


4.
   line 15 : pet_name = cat_name

   We are assigning address of first byte of cat_name
   to pet_name

5.
   buffer[3] : 4th element = 4th character of \'Mittens\'
   Ans: t

 jacqueli@ug28:-/midterm>cat -n problem1.c #include #include #define SIZE 64 char buffer [SIZE]; int main (int argc, char *argv (]) (char * cat_name = \

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site