C के Extended Data Types
In this page:
unsigned data_type variable_name = value;
short variable_name = value;
long variable_name = value;
long long variable_name = value;
Extended Data Types क्या हैं?
Extended data types int या char जैसे base type को modifiers -- short, long, signed, और unsigned -- के साथ combine करते हैं जो इसका size, range, या यह negative values represent कर सकता है या नहीं यह adjust करते हैं।
उदाहरण: What are Extended Data Types?
// Include standard input/output (printf, scanf)
#include <stdio.h>
// Program execution starts in main()
int main() {
// Declare small and set it to 100
unsigned short small = 100;
// Print formatted text to the screen
printf("%hu", small);
// Return 0 to signal that the program finished successfully
return 0;
}
Login to try C/C++/Java/PHP code in the editor
short और long Modifiers
short और long modifiers एक integer type का typical size adjust करते हैं: short आमतौर पर छोटी range के लिए कम bytes इस्तेमाल करता है, जबकि long आमतौर पर values की एक बड़ी range accommodate करने के लिए ज़्यादा bytes इस्तेमाल करता है।
उदाहरण: short and long Modifiers
// Include standard input/output (printf, scanf)
#include <stdio.h>
// Program execution starts in main()
int main() {
// Declare s and set it to 100
short s = 100;
// Declare l and set it to 1000000L
long l = 1000000L;
// Print formatted text to the screen
printf("%hd %ld", s, l);
// Return 0 to signal that the program finished successfully
return 0;
}
Login to try C/C++/Java/PHP code in the editor
signed और unsigned Modifiers
signed और unsigned modifiers control करते हैं कि एक integer type negative numbers represent कर सकता है या नहीं: signed अपनी range को negative और positive values के बीच बांटता है, जबकि unsigned पूरी range को positive values और zero को dedicate करता है।
उदाहरण: signed and unsigned Modifiers
// Include standard input/output (printf, scanf)
#include <stdio.h>
// Program execution starts in main()
int main() {
// Declare s and set it to -5
signed int s = -5;
// Declare u and set it to 5
unsigned int u = 5;
// Print formatted text to the screen
printf("%d %u", s, u);
// Return 0 to signal that the program finished successfully
return 0;
}
Login to try C/C++/Java/PHP code in the editor
बहुत बड़े Numbers के लिए long long
long long, C99 में introduce हुआ, कम से कम 64 bits storage guarantee करता है, इसे standard choice बनाते हुए जब कोई value अलग-अलग systems पर int या long reliably जितना hold कर सकता है उससे ज़्यादा हो सकता है।
उदाहरण: long long for Very Large Numbers
// Include standard input/output (printf, scanf)
#include <stdio.h>
// Program execution starts in main()
int main() {
// Declare big and set it to 9000000000LL
long long big = 9000000000LL;
// Print formatted text to the screen
printf("%lld", big);
// Return 0 to signal that the program finished successfully
return 0;
}
Login to try C/C++/Java/PHP code in the editor
सही Extended Type चुनना
सही extended type चुनने का मतलब है memory usage को actually चाहिए होने वाली values की range के against balance करना: एक छोटा हमेशा-positive count unsigned char में fit होता है, जबकि एक billion से ज़्यादा हो सकने वाली value को long long चाहिए।
उदाहरण: Choosing the Right Extended Type
// Include standard input/output (printf, scanf)
#include <stdio.h>
// Program execution starts in main()
int main() {
// Declare smallCount and set it to 200
unsigned char smallCount = 200;
// Declare largeValue and set it to 5000000000LL
long long largeValue = 5000000000LL;
// Print formatted text to the screen
printf("%u %lld", smallCount, largeValue);
// Return 0 to signal that the program finished successfully
return 0;
}
Login to try C/C++/Java/PHP code in the editor
- एक plain
intमेंintसे बड़ी value store करना, जैसे 3000000000, जो overflow cause करता है। - एक
long longको%lldकी बजाय%dसे print करना, जो garbage print करता है। - यह मान लेना कि
longका size हर platform पर same है, जब यह कुछ systems पर 4 bytes और दूसरों पर 8 है।
Chapter Quiz — Complete all 21 topics to unlock
0/21 topics done
Complete these topics first:
- C Introduction
- C History & Features
- C Environment Setup
- C First Program
- C Syntax & Structure
- C Statements
- C Comments
- C Keywords & Identifiers
- C Data Types
- C Character Data Type
- C Numeric Data Types
- C Decimal (Floating-Point) Numbers
- C sizeof Operator
- C Extended Data Types
- C Type Conversion
- C Booleans
- C Variables
- C Changing Variable Values
- C Multiple Variables
- C Constants
- C Fixed-Width Integers