**C programming**, if you are a beginner or new in programming then you must have learned C programming First because in C programming you will learn the root of programming if you have the basic knowledge of programming then you can easily learn other Programming languages like

**C++, Java, Python, android, etc.**because in these languages only syntaxes are changes but the logic remains same so you must have to learn C programming First so you can understand another language easily.

When you Learn

**C Programming**, There is a basic Data type Like Integer, Flot, Character, etc. and this data type used to solve the problem like adding two no. or find an average number or swapping two numbers, etc. in C programming.

In

**C programming**, You must know that if we want to print a Character value then we have to write

**"%c"**let's assume that the Character word is starting from

**'C'**so we write

**"%c"**or if we want to print a String value then we have to right

**"%s"**let's assume that String word is starting from

**'S'**so we write

**"%s"**and if we want to print a floating number then we have to write

**"%f"**let's assume that Floating word is starting from

**'F'**so we write

**"%f"**.

But when we talk about integer number which is Starting from

**'I'**then why not we use

**"%i"**in the place of

**"%d"**?

### This is the main reason:

**Integer Constant**is divided into three categories.

- Decimal
- Octal
- Hexadecimal

**1. Decimal number:**Decimal Number is varied from

**0 to 9**(0,1,2,3,4,5,6,7,8,9). it is the set of 10 digits which is from 0 to 9.

**2. Octal Number:**Octal number is varied from

**0 to 7**(0,1,2,3,4,5,6,7). it is a set of 8 digits which is from 0 to 7.

**3.**

**Hexadecimal**: Hexadecimal is varied from

**0 to 15**, but its output will come in this manner from 0 to 9 it will print as it is digits but after 9 that means 10 to 15 it will print A, B, C, D, E, F here

**A=10, B=11, C=12, D=13, E=14, and F=15.**

When you want to print an Integer constant in Decimal number or Octal number or Hexadecimal then you have use

**"%d" for Decimal or "%o" for Octal or "%x' for Hexadecimal**number but here mostly Maths calculation is in Decimal form so we write "%d" so that we can get a Decimal number as an Output.

Let's see some examples and you can try this in your compiler (or Online C compiler) that how does vary the integer constant value in Decimal number or Octal number or Hexadecimal number.

#include <stdio.h>

void main()

{

int a=12;

printf("%d\n",a); //for Decimal Number

printf("%o\n",a); //for Octal Number

printf("%x\n",a); //for Hexadecimal Number

}

OUTPUT:

12

14

C

## No comments:

## Post a Comment

What do you think about this article? just write your feedback in the comment box. Thanks :)