Writing a function in C language to print the contents of the arr array
requires not to use array subscripts but to use pointers.
arr is an integer one-dimensional array.
Problem analysis:
First define an integer array
and then create a pointer variable p pointing to the array arr, that is, p = arr[0];
traverse the array and output each bit (pointer p dereference)
and *(p+1) = arr[1 ]. The array is integer, +1 is equal to byte + 4 is the next element of the array.
code show as below:
#include<stdio.h>
int main()
{
int arr[] = {
1, 2, 3, 4, 5, };
int* p = arr;
for (int i = 0; i < 5; i++){
printf("%d ", *(p + i));
}
return 0;
}
operation result: