-
Notifications
You must be signed in to change notification settings - Fork 0
/
pointers_and_array.c
29 lines (27 loc) · 1.3 KB
/
pointers_and_array.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <stdio.h>
int main()
{
// char a = '3';
// char* ptra = &a;
// printf("%d\n", ptra);
// ptra--;
// printf("%d\n", ptra);
// printf("%d", ptra-2);
int arr[] = {311,52,3,4,5,6,67};
int* arrayptr = arr;
printf("Value at position 3 of the array is %d\n", arr[3]);
printf("The address of first element of the array is %d \n", &arr[0]);
printf("The address of first element of the array is %d \n", arr);
printf("The address of second element of the array is %d \n", &arr[1]);
printf("The address of second element of the array is %d \n", arr + 1);
printf("The address of third element of the array is %d \n", &arr[2]);
printf("The address of third element of the array is %d \n", arr + 2);
// arr--; // this line will throw an error
printf("The value at address of first element of the array is %d \n", *(&arr[0]));
printf("The value at address of first element of the array is %d \n", arr[0]);
printf("The value at address of first element of the array is %d \n", *(arr));
printf("The value at address of second element of the array is %d \n", *(&arr[1]));
printf("The value at address of second element of the array is %d \n", arr[1]);
printf("The value at address of second element of the array is %d \n", *(arr + 1));
return 0;
}