ProgrammingHardProduct company OA
What is the type of the result of subtracting two int pointers, p - q?
- A. ptrdiff_t, a signed integer type defined in <stddef.h>
- B. size_t, because sizes are never negative
- C. int *, the same type as the operands
- D. unsigned int
Correct answer: A. ptrdiff_t, a signed integer type defined in <stddef.h>
Pointer subtraction gives the distance in elements as a signed ptrdiff_t, since q may be after p. It is printed with %td. size_t is what sizeof yields and is unsigned.
More C Programming questions
- What is printed? c char s[] = "xya", p = s; char a = p++; char b = ++p; char c = ++p; printf("%c%c%c %s", a, b, c, s);
- What is printed? c int hs(unsigned n) { return n ? (n & 0xF) + hs(n >> 4) : 0; } int main(void) { printf("%d", hs(0xBEEF)); }
- How many swaps does this bubble sort make? c int a[] = {3, 1, 4, 1, 5}, sw = 0; for (int i = 0; i < 5; i++) for (int j = 0; j < 4 - i…
- What is printed? c printf("%d %d", strncmp("abc", "abd", 2) == 0, strncmp("ab", "ab0x", 5) == 0);
- uint8t a = 200, b = 100; uint8t c = a + b; What is the value of c?
- With uint32t x = 5u - 7u; what is the value of x?