A variable i of type int is stored in memory location 0x22ff74. Now assuming that I have a pointer to i , What does the following C/C++ code produce as output.(assume standard sizes) int main() { int i=20; int *ptr=&i; ptr=ptr-1; cout<
-
0x22ff74
-
0x22ff70
-
0x22ff73
-
Compiler error
-
19
B
Correct answer
Explanation
Pointer arithmetic scales by the size of the pointed-to type. On a 32-bit system, int is typically 4 bytes. When you subtract 1 from an int pointer, it decreases by 4 bytes (not 1 byte). So if ptr points to 0x22ff74, ptr-1 points to 0x22ff70. This is a fundamental property of pointer arithmetic in C/C++.