If the picture is clear to you, (right click) on the picture, then click (open t
ID: 3816638 • Letter: I
Question
If the picture is clear to you, (right click) on the picture, then click (open the picture in a new tap).
Lab 11: Pointers Pointers are variables that store the address of a memory location. They are called pointers because they point to the memory location whose addres ley store. For example, if the pointer variable p stores the value B1A2 then it points to' memory location B1A2 (Memory addresses are usually labeled using hexadecimal. Hexadecimal is simply a base 16 counting system In a base 16 system we need symbols to stand for the values 10 throug Sand the ers A through Fare used. So, B n hexadecima For example, B1A2 163 1 16 4-10 16 2*16 ch is 11 4096 1 256 1016 2 45066 2 45474 236 Pointers are declared using a For example, the statement: C++ style int* p C style int p e) called p that can point to a memory location creates a pointer Varna toring an integer emory locations storing other types. can also pol but that will lead to big problems n this case we haven't made p point anywhere yet The following code illustr ates using pointers create a pointer int *pi inti 5; create an integer variable make p point to i &i; change the value in the location p points to cout i prints -6 i has magically changed cout p; also print 6 To make a pointer point to a regular variable we used the syn &i;). To access the value a pointer is pointing to we used the symbol p 6:). You can also change where a pointer points to, that is change what memory location it stores, by using operators like p++;). This would ncrease the memory location stored in the pointer, which makes the pointer point to a later memory location. (The amount that adds to a pointer's location depends on the type he pointer is d eclared to point to. For example, if a pointer p points to chars men typically changes the memory value stored by p by 1 byte because chars take up 1 byte in memory.) Exercise 11 The following code demonstrates some of the different ways pointers can manipulate values in memory. When you compile and run the code you w see that the array is initially "abedef" and ends up as "xxxxxx You need out on which line each of the origi etters is changed to an 1 #include kiostrean> 2 using namespace std; 3 void funcl (char *q) A int main() t 5 char array 0 abcdef char *p cout initial array array end array 3 10 &array;[1] 11 12 13 pa &array; 130 p[2] 14 15 16 func (p 17 func1 (array 18 func1(karray C3) 19 cout final array array en dl. 20 21 void funcl (char *g 22 q 23 24 You only need to tumin alist saying the line number that changed a given etter. For e xample, the a was changed on nber 6. which clearly isn't correct For letters changed in the function ve the line number inExplanation / Answer
Answer
1. 'a' replace with 'x' at line no 9.
2. 'c' replace with 'x' at line no 12.
3. 'f' replace with 'x' at line no 14.
4. 'd' replace with 'x' at line no 16 during the function call.
4. 'b' replace with 'x' at line no 17 during the function call.
4. 'e' replace with 'x' at line no 18 during the function call.