hello.,
ny1 knows what is the data type for displaying hex numbers? i know that specifier is %x, but dont know what data type it is
ex: 0xBCD

thanx!

Dani AI

Generated

A quick clarification and a few practical tips that build on ’s question and ’s example.

C chooses the exact type for an unsuffixed hexadecimal literal using a fixed preference list (for hex/octal: int, unsigned int, long, unsigned long, long long, unsigned long long). Adding suffixes (U, L, LL) forces unsigned/long/long long. This matters because the chosen type determines which printf length modifier you must use. See the C integer-constant rules for details (integer constant rules).

Printf requires the conversion to match the argument type; mismatches are undefined behavior. For portable hexadecimal output prefer fixed-width unsigned types with the inttypes.h macros (they pick the right conversion string for you). Example:

#include <stdio.h>
#include <inttypes.h>
#include <stdint.h>

uint32_t v = 0xABCDu;
printf("0x%" PRIx32 "\n", v);

Avoid common pitfalls: printing a signed value with a hex conversion can show two’s-complement bit patterns on many systems but is undefined by the standard; large unsuffixed hex literals may become unsigned automatically; and using the wrong length modifier (missing L/LL) will break portability. For format-specifier details and the PRIx macros see the C I/O and inttypes.h references (fprintf/printf formats, inttypes.h macros).

You declare it as an integer.
Ex:

int hex = 0xBCD;
printf("%x",hex);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.