
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
Difference between %d and %i format specifier in C
Format Specifier %d
The format specifier %d takes integer value as a signed decimal integer value which means values should be decimal whether it is negative or positive.
Here is an example of format specifier %d in C language,
Example
#include <stdio.h> int main() { int v1 = 7456; int v2 = -17346; printf("The value in decimal form : %d
", v1); printf("The value in negative : %d", v2); return 0; }
Output
The value in decimal form : 7456 The value in negative : -17346
Format Specifier %i
The format specifier %i takes integer value as an integer value which means values should be decimal, octal and hexadecimal and octal value is provided by preceding ‘0’ while hexadecimal value is provided by preceding ‘0x’.
Here is an example of format specifier %i in C language,
Example
#include <stdio.h> int main() { int v1 = 1327; int v2 = 0x42451; printf("The value in decimal form : %d
", v1); printf("The value in hexadecimal form : %i", v2); return 0; }
Output
The value in decimal form : 1327 The value in hexadecimal form : 271441
- Related Articles
- Difference between %d and %i format specifier in C language.
- C# Decimal ("D") Format Specifier
- Long Date ("D") Format Specifier in C#
- Short Date ("d") Format Specifier
- C# Currency ("C") Format Specifier
- Sortable ("s") Format Specifier in C#
- C# Hexadecimal ("X") Format Specifier
- C# Exponential (“E”) Format Specifier
- C# Percent ("P") Format Specifier
- C# Numeric (“N”) Format Specifier
- Month ("M", "m") Format Specifier in C#
- Short Time ("t") Format Specifier in C#
- Long Time ("T") Format Specifier in C#
- Year Month ("Y") Format Specifier in C#
- The "0" custom format specifier in C#

Advertisements