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

Define a string a by char a[] = \"The Monkey acts crazy\"; Also, define a variab

ID: 3624669 • Letter: D

Question

Define a string a by
char a[] = "The Monkey acts crazy";
Also, define a variable p of type “pointer to char”.

(a) Use the pointer variable to store the address of the first character of your array.
(b) Print out the value of the first element of the array and its address, that is the number of the memory location used to store the value. Note that you will need to use the
conversion character %p to print a value stored in a pointer variable.
(c) Add 26 to the pointer variable and using the indirection operator print out the value stored at this memory location. Note: it should be the last character of your string.
(d) The next stored character should be the null character. Print this character, too.

Explanation / Answer

char a[] = "The Monkey acts crazy";

a)

char* p = (char*)a;

b

printf("%x %c ", p, *p);

c)

p = p+26;
printf("%c ", *p);

d)

p = p+1;
printf("%c ", *p);

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote