← Back to C Course | Chapter 1: Introduction & Basics | Lesson 14 of 21

C के Extended Data Types

Extended data types एक base type को modifiers -- short, long, signed, और unsigned -- के साथ combine करते हैं जो इसका size, range, या negative numbers represent करने की क्षमता adjust करते हैं।
Syntax
c
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?

c
// 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;
}

short और long Modifiers

short और long modifiers एक integer type का typical size adjust करते हैं: short आमतौर पर छोटी range के लिए कम bytes इस्तेमाल करता है, जबकि long आमतौर पर values की एक बड़ी range accommodate करने के लिए ज़्यादा bytes इस्तेमाल करता है।

उदाहरण: short and long Modifiers

c
// 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;
}

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

c
// 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;
}

बहुत बड़े 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

c
// 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;
}

सही 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

c
// 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;
}
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. एक plain int में int से बड़ी value store करना, जैसे 3000000000, जो overflow cause करता है।
  2. एक long long को %lld की बजाय %d से print करना, जो garbage print करता है।
  3. यह मान लेना कि long का size हर platform पर same है, जब यह कुछ systems पर 4 bytes और दूसरों पर 8 है।

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.