If the pointer is decremented by 1, will the memory address decreases by 4 (int)? | Sololearn: Learn to code for FREE!
+ 3

If the pointer is decremented by 1, will the memory address decreases by 4 (int)?

#include <stdio.h> int main() { int a[5] = {22, 33, 44, 55, 66}; int *ptr = NULL; ptr = &a[4]; /* point to the fifth array element */ printf("%d %x\n", *ptr, ptr); /* 66 */ ptr--; printf("%d %x\n", *ptr, ptr); /* 55 */ return 0; } /*If the pointer is decremented by 1, will the memory address decreases by 4 (int)? */

30th Dec 2018, 12:51 PM
Konybud
Konybud - avatar
4 Answers
+ 2
You already got your answer from your program, 4
30th Dec 2018, 1:02 PM
Calviղ
Calviղ - avatar
+ 2
Ok
30th Dec 2018, 1:11 PM
Konybud
Konybud - avatar
+ 2
Yes
22nd Jan 2019, 6:29 PM
parag sahu
parag sahu - avatar
+ 1
That is like your other question something you can figure out by checking this in Playground! Increment the adress, print it out, compare it. Then try it with shorts or another type.
30th Dec 2018, 1:02 PM
HonFu
HonFu - avatar