ProgrammingHardGATE CS · Campus placements
int n = -1; uint64_t u = (uint64_t)n; What is u?
- A. 18446744073709551615
- B. -1
- C. 0
- D. 9223372036854775807
Correct answer: A. 18446744073709551615
Converting a negative value to an unsigned type is defined as modular arithmetic: -1 plus 2^64 gives 18446744073709551615. This is the conversion used when a negative number is mixed into unsigned arithmetic.
More C Programming questions
- uint32t fib(int n) iteratively computes a = 0, b = 1, then n times: t = a + b; a = b; b = t, with all arithmetic in uint32t. What is…
- int x = 5; x = x++; What is the outcome of this statement?
- uint16t h = 0; for each character c of "ABCDE", h = h 31 + c; with 65 for 'A' and so on. What is h at the end?
- Which function correctly tests whether an unsigned value x is a power of two, with x = 0 excluded?
- char b[6]; snprintf(b, sizeof b, "%s-%d", "abcdef", 12345); int r = snprintf(NULL, 0, "%s-%d", "abcdef", 12345); printf("%s %d", b, r)…
- char b[5]; / stdin holds the nine bytes: abcdefgh and a newline / int calls = 0; do { fgets(b, sizeof b, stdin); calls++; } while…