Multiple choice technology programming languages

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<

  1. 0x22ff74

  2. 0x22ff70

  3. 0x22ff73

  4. Compiler error

  5. 19

Reveal answer Fill a bubble to check yourself
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++.