move exercises, lecture examples, labs into subfolders
This commit is contained in:
22
Exercises/C15/pointer_array_example_2.c
Normal file
22
Exercises/C15/pointer_array_example_2.c
Normal file
@@ -0,0 +1,22 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
// Declare an integer array and an integer pointer
|
||||
int MyArray[10] = {2,4,6,8,10,12,14,16,18,20};
|
||||
int *pI;
|
||||
|
||||
// Get the start address by asking for the address iof array item [0]
|
||||
pI = &MyArray[0]; // Or use: pI = MyArray;
|
||||
|
||||
// Display the 1st item in the array, first be accessing rhe array
|
||||
printf("The value at array item [0] is %d\n", MyArray[0]);
|
||||
|
||||
// Since the pointer points to the address of the 1st item we can
|
||||
// access it as we would for a pointer pointing to any single variable
|
||||
|
||||
printf("The value at the memory address held in pI is %d\n", *pI);
|
||||
|
||||
return 0; // Exit
|
||||
}
|
||||
Reference in New Issue
Block a user