Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

CpSe 1111 Lab 12 Pointers Overview Pointers are an integral part of C and C+. Wh

ID: 3704531 • Letter: C

Question

CpSe 1111 Lab 12 Pointers Overview Pointers are an integral part of C and C+. While they may be the cause of many headaches, they allow for a great deal of control and flexibility. Because they are low-level constructs, they roquire a solid understanding of the memory model behind it all Not every language has pointers, but what you learn about memory management will apply to most every language. Unlike most of your previous labs this semester, this one will not require you to write and submit a program. This lab is adapted from a lab used elsewhere, and it involves a good amount of guided self-exploration. We'll give you the right questions to ask along the way. Many of the questions will be open-ended, so when answering them, be sure to ask if you are not 100% sure what's going on! Please use the answer sheet provided. You will submit the answer sheet to the handin page. You may workindividually or in groups of no more than3 The code snippets here are screenshots, so you won't be able to copy and paste them (sorry') but they re short enough to type. This lab will give you the opportunity to: .Understand and use pointers and pointer operations .Discover the relationship between arrays and pointers . Explore passing pointers as function parameters Warm U First, let's practice with pointers to basic C data types and some related pointer operations. We'll see referencing. dereferencing, and arithmetic operations. I. Compile and run this program: 1 #include «stdio.h> 3 int main(int argc, chare argvl) int integerl, »pi. *p2: integer! 10; pl-&integerl; 10 printf("integerl= td ". integer!) ; 11 printf pl Spn". pl): 12 printf p2 pin", p2) 13 return : 2. Suppose after the declaration of the variables on line 4, we have the following: Symbol Table: Name ype int x7fft8cift994 XTEFF8c115988 int Memory Chunk (address on the left, data on the right 0x7fEtBciff994 0x7fff8cif1988 0x7fff8c1ff980 a. Fill in the above memory chunk table to reflect the changes that lines 6,7, and 8 cause.

Explanation / Answer

Question 2:

a.

b. integer1= 11

*p1 referes to the location 0x7fff8c1ff994 and the ++ operator increase the value by 1 in that location. It already having 10 which increase to 11.

c. Yes, same. integer1= 11
integer1 holding value 10 already and ++ operator increase its value by 1. so it is 11.

d. No, not same. According to operator precedence both * and ++ are same precedence, but associativity is right to left.

Question 3:

p2 represent a character pointer. This program can compile with the warning "assignment from incompatible pointer type". p1 is an integer pointer and p1 assigned to p2 which gives the warning. In some case we want to access a single byte data from an integer in such case we can assign integer pointer to character pointer to access single byte data.

Address Value 0x7fff8c1ff994 10 0x7fff8c1ff988 0x7fff8c1ff994 0x7fff8c1ff980 0x7fff8c1ff988