Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

CS 223 In class exercise – pointers and arrays

Variable declaration and initialization

1. Declare an integer variable iNum and assign number 11 to it as its initialization value.

2. Declare a double variable dNum and assign floating point 22.22 to it as its initialization value.

3. Declare a character variable cVar and assign character ‘X’ to it as its initialization value.

4. Declare an array of 4 integers iArray and initialize its elements using numbers 3, 4, 5, 6.

5. Declare an array of 3 doubles dArray and initialize its elements using following floating point
values 0.7, 0.8, and 0.9.

6. Declare an array of characters cArray and initialize it using string “Hello world!”.

7. Declare an integer pointer iNum_ptr , and then assign it with the address of iNum variable.

8. Declare a double pointer dNum_ptr , and assign it with the address of dNum variable.

9. Declare a char pointer cVar_ptr , and assign it with the address of cVar.
10. Declare an integer pointer iArray_ptr , and assign it with the address of the integer array
iArray, i.e. the address of the first element in the array.

11. Declare a double pointer dArray_ptr and assign the address of dArray to it, i.e. the address of
the first element in the double array dArray.

12. Declare a char pointer cArray_ptr , and assign it with the address of cArray, i.e. the address of
its first element in the char array cArray.

Answer the following questions:

1. Write expressions to get the address of each element in the integer array iArray:

________________ _________________ __________________ ___________________

2. Write expressions to get the address of each element in the double array dArray:

___________________ ____________________ _______________________

3. Using pointer dNum_ptr, modify the value, that the pointer is pointing at, to 3.1415

4. Using pointer iArray_ptr, change the value of the last element in the 4-integer array, that the
pointer points at, to 1000.

You might also like