[Solved] What is this C function doing?


This code accepts a decimal value and prints the hexadecimal representation.

Try it out yourself

In C we can use the %x (%X) format specifier flag to printf to do it for us:

printf("%X", 16); // 10
printf("\n");
printf("%X", 42); // 2A

If you’re using a C++ compiler, we can instead use the std::hex stream manipulation flag on iostream to achieve the same result:

std::cout << std::hex << 16 << std::endl; // 10
std::cout << std::hex << 42 << std::endl; // 2a

4

solved What is this C function doing?