ProgrammingHard
Which statement about left-shifting a negative signed integer in C is correct?
- A. It is undefined behaviour, so shifts of negative signed values must be avoided
- B. It always gives the arithmetic result multiplied by two
- C. It is defined and gives a positive value
- D. It is defined only on two's-complement machines by the standard
Correct answer: A. It is undefined behaviour, so shifts of negative signed values must be avoided
C leaves a left shift of a negative signed value undefined, so code should shift an unsigned copy instead.
More C Programming questions
- How many subsets of {1, 2, 3, 4} (including the empty set) have XOR equal to 0?
- What is the result of (0xFFu >> 4) | (0x0Fu << 4) & 0xFF?
- How many times does cnt++ run in: for (i = 0; i < 10; i++) for (j = i; j < 10; j++) cnt++; ?
- How many iterations does for (i = 1; i < 1024; i = 2) do?
- A binary search over n = 10^6 sorted records, in the worst case, takes how many loop iterations?
- A sieve of Eratosthenes up to n = 100 marks composites by starting each prime p at pp, and only for pp <= n. How many marking operations…