In the following program, we will see how to initialize the variables with decimal, octal & Hex values.

#include <stdio.h>

int main(void) {
	
  // Following is way to initialize the variables with decimal, octal & hexa decimal.
  int decimal_variable = 10;
  int octal_variable = 012;
  int hexa_variable = 0xa;
		
  // print decimal_variable as hexa
  printf("Decimal value %d in Hexa is %X \n", decimal_variable, decimal_variable);
  
  // print decimal_variable as octal
  printf("Decimal value %d in Octal is %o \n",decimal_variable,  decimal_variable);
  
  // Print octal_variable as decimal
  printf("Octal value %o in Decimal %d \n", octal_variable, octal_variable);
  
  // Print octal_variable as hexa
  printf("Octal value %o in Hexa %X \n", octal_variable, octal_variable);
  
  // Print Hexa as decimal
  printf("Hexa value %X in Decimal %d \n", hexa_variable, hexa_variable);
  
  // Print Hexa as decimal
  printf("Hexa value %X in Octal %o \n", hexa_variable, hexa_variable);
  
  return 0;
}

Output:

Decimal value 10 in Hexa is A 
Decimal value 10 in Octal is 12 
Octal value 12 in Decimal 10 
Octal value 12 in Hexa A 
Hexa value A in Decimal 10 
Hexa value A in Octal 12 

Explanation

We must use 0, 0x notations as shown in the above example while initializing the octal and Hex values.

To print the values in decimal, octal & hexadecimal formats we have to use the %d %o, %X format specifiers in print.

What are Binary, Decimal, Octal & Hexadecimal values?
In this article, I explain Binary, decimal and octal numbers with examples. Binary values are also known as Base 2 values.
Decimal to binary, octal & hexadecimal?
In this article, We learn how to convert binary to Decimal to binary, octal and hexadecimal values.
Binary to Decimal, Octal and Hexadecimal?
In this article, I explain the binary to decimal, octal & hexadecimal conversions. Consider a binary value with n binary digits, where ‘n’ is the...
Octal to Binary, Decimal, Hexadecimal?
In this article, I explain the Octal to Binary, Decimal & Hexadecimal conversion. We know that octal values are base 8 values...
Hexadecimal to binary, octal & decimal
In this article, We discuss hexadecimal to binary, octal & decimal conversions. Each hex digit is in the range of [0-F]. To represent a hex digit...