(1) Declare a char array called alpha, and initialize it to the string “ABCDEFGHIJKLMNOPQRSTUVWXYZ”. In your declaration, make the alphabet array read-only, so none of the letters in the array can be changed later in the program.
const char alpha[] = "ABCDEFGHIJKLMOPQRSTUVWXYZ";
(is 'const' what makes the array read-only?)
------------------------------------------------------------------
(2) Given a char pointer called ptr (i.e. char *ptr) and the alpha array declared in problem (1) above, make ptr point to the letter ‘D’ in the alpha array (i.e. set ptr to the memory address where ‘D’ is stored).
This one I have issues with a lot. I am assuming something like:
prt = *(alpha+4);
------------------------------------------------------------------
(3) What’s wrong with the code below? (Circle the line with the error, and describe the error):
Code:
int *int_ptr;
int primes[ ] = { 2,3,5,7 };
int composite[ ] = {4,6,8,9};
int_ptr = primes;
composite = int_ptr; //This is the wrong line, I think
^^I am not sure exactly how to explain that the last line is the wrong code.
------------------------------------------------------------------
(4) Pointers enable passing variables to functions by: (Answer in bold)
A. Pass by value
B. Pass by reference
C. Pass by number
D. Pass by operator