Practice mode C Language

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.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.