pointer arithmetic c

Solutions on MaxInterview for pointer arithmetic c by the best coders in the world

showing results for - "pointer arithmetic c"
Lyndon
10 May 2018
1ptr++
2
Michael
08 Sep 2016
1#include <stdio.h>
2
3const int MAX = 3;
4
5int main () {
6
7   int  var[] = {10, 100, 200};
8   int  i, *ptr;
9
10   /* let us have array address in pointer */
11   ptr = &var[MAX-1];
12	
13   for ( i = MAX; i > 0; i--) {
14
15      printf("Address of var[%d] = %x\n", i-1, ptr );
16      printf("Value of var[%d] = %d\n", i-1, *ptr );
17
18      /* move to the previous location */
19      ptr--;
20   }
21	
22   return 0;
23}
Jasmine
23 Jun 2020
1#include <stdio.h>
2
3const int MAX = 3;
4
5int main () {
6
7   int  var[] = {10, 100, 200};
8   int  i, *ptr;
9
10   /* let us have array address in pointer */
11   ptr = var;
12	
13   for ( i = 0; i < MAX; i++) {
14
15      printf("Address of var[%d] = %x\n", i, ptr );
16      printf("Value of var[%d] = %d\n", i, *ptr );
17
18      /* move to the next location */
19      ptr++;
20   }
21	
22   return 0;
23}
Michelle
18 May 2018
1#include <stdio.h>
2
3const int MAX = 3;
4
5int main () {
6
7   int  var[] = {10, 100, 200};
8   int  i, *ptr;
9
10   /* let us have address of the first element in pointer */
11   ptr = var;
12   i = 0;
13	
14   while ( ptr <= &var[MAX - 1] ) {
15
16      printf("Address of var[%d] = %x\n", i, ptr );
17      printf("Value of var[%d] = %d\n", i, *ptr );
18
19      /* point to the next location */
20      ptr++;
21      i++;
22   }
23	
24   return 0;
25}
Matthew
09 Feb 2017
1Address of var[0] = bf882b30
2Value of var[0] = 10
3Address of var[1] = bf882b34
4Value of var[1] = 100
5Address of var[2] = bf882b38
6Value of var[2] = 200
7