
- 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 language.
Format Specifiers
In C programming language, %d and %i are format specifiers as where %d specifies the type of variable as decimal and %i specifies the type as integer. In usage terms, there is no difference in printf() function output while printing a number using %d or %i but using scanf the difference occurs. scanf() function detects base using %i but assumes base 10 using %d.
Example (C)
#include <stdio.h> int main() { int num1 ,num2; int num3, num4; scanf("%i%d",&num1 , &num2); printf("%i\t%d
",num1, num2); num3 = 010; num4 = 010; printf("%i\t%d",num3, num4); return 0; }
Output
32767-498932064 8 8
Here 010 is an octal number. scanf read the number as 10 using %d and read the number as 8 using %i. printf is good in both case to read the number as octal.
- Related Articles
- Difference between %d and %i format specifier in C
- 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# Exponential (“E”) Format Specifier
- C# Percent ("P") Format Specifier
- C# Numeric (“N”) Format Specifier
- C# Hexadecimal ("X") 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