
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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
Advertisements