ProgrammingVery hardGATE CS · Campus placements
Which statement about pointer relations in C is well defined?
- A. Comparing pointers into different arrays with < is well defined
- B. Comparing pointers into the same array with < is well defined when both point into it or one past its end
- C. Subtracting pointers from different arrays is well defined
- D. Dereferencing one past the end of an array is well defined
Correct answer: B. Comparing pointers into the same array with < is well defined when both point into it or one past its end
Relational comparison is defined within one array, including the one-past-the-end address. Comparing or subtracting unrelated pointers is undefined, and dereferencing the one-past-the-end address is undefined.
More C Programming questions
- How many subsets of {0, 1, 2, 3, 4, 5} contain exactly three elements?
- #define DOUBLE(x) (x + x). What does printf("%d", DOUBLE(2) 3) print?
- uint8t x = 0x90; uint8t y = x & (uint8t)(x - 1); What is y?
- int f(int n) { if (n == 0) return 0; return n % 2 + f(n / 2); } What is f(37)?
- For unsigned int i = 3; i >= 0; i--, what happens to the loop body?
- char a[] = "hi"; char b[] = "hi"; What does a == b evaluate to?