What is printed by this C code: printf(“%ld”, strtol(“ff”, NULL, 16));?
Correct answer C. 255
Explanation
strtol converts a string to long in the base given by the third argument. In base 16 the digits f and f mean 15 * 16 + 15 = 255. Passing NULL as the end pointer simply means you do not need to know where parsing stopped. Base 0 would detect the base from a prefix such as 0x, and strtol sets errno to ERANGE when the value overflows.
Answer checked How we write and check questions
Discussion