Home / Programs / Unsigned Hexadecimal for integer : %x, %X Example Program
Programming Example

Unsigned Hexadecimal for integer : %x, %X Example Program

👁 998 Views
💻 Practical Program
📘 Step by Step Learning
Unsigned Hexadecimal for integer : %x, %X Example Program

Program Code

#include <stdio.h> 
int main() 
{ 
    int a = 15; 
    printf("%x\n", a); 
    return 0; 
}

Output

f

Explanation

Unsigned Hexadecimal for integer

printf("%x\n", a); 

The given code is a C program that prints the hexadecimal representation of the integer value 15 using the printf() function with the format specifier %x.

Here's how it works:

  • The #include line includes the standard input/output library in the program.
  • The main() function is the entry point of the program.
  • The variable a is declared as an integer and assigned the value 15.
  • The printf() function is used to display the hexadecimal representation of a using the %x format specifier.
    • %x is a format specifier used to display an integer in hexadecimal (base 16) format using lower-case letters.
  • The \n character is used to insert a newline after the output is printed.
  • Finally, the return 0; statement terminates the program and returns 0 to the operating system indicating that the program executed successfully.

How to learn from this program

First read the algorithm, then study the program code line by line. After that, compare the code with the output and finally go through the explanation. This approach helps learners understand both the logic and the implementation properly.