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

C के Data Types

Data types C को बताते हैं कि एक value किस तरह की चीज़ है, जैसे whole numbers, decimals, या single letters। यह अलग-अलग items के लिए अलग-अलग आकार के boxes रखने जैसा है।
Syntax
c
data_type variable_name = value;

// e.g. int, char, float, double

Integer Type

int बिना किसी fractional part के whole numbers store करता है, आमतौर पर modern systems पर 4 bytes memory इस्तेमाल करते हुए, जो इसे लगभग -2 billion से +2 billion तक की range देता है -- counters, indexes, और ज़्यादातर everyday integer math के लिए काफी ज़्यादा।

उदाहरण: Integer Type

c
// Include standard input/output (printf, scanf)
#include <stdio.h>
// Program execution starts in main()
int main() {
	// Declare count and set it to 100
	int count = 100;
	// Print formatted text to the screen
	printf("%d, size: %zu bytes", count, sizeof(count));
	// Return 0 to signal that the program finished successfully
	return 0;
}

Character Type

char exactly 1 byte में एक single character store करता है, लेकिन internally यह असल में सिर्फ एक छोटा integer है जो ASCII table में उस character की position represent करता है -- यही वजह है कि आप C में char values पर सीधे arithmetic कर सकते हैं।

उदाहरण: Character Type

c
// Include standard input/output (printf, scanf)
#include <stdio.h>
// Program execution starts in main()
int main() {
	// Declare grade and set it to 'A'
	char grade = 'A';
	// Print formatted text to the screen
	printf("%c is ASCII %d", grade, grade);
	// Return 0 to signal that the program finished successfully
	return 0;
}

Floating-Point Type

float 4 bytes और लगभग 6-7 significant digits की precision इस्तेमाल करके decimal numbers store करता है, जो कई everyday calculations के लिए काफी है लेकिन currency जैसी exact decimal accuracy चाहने वाली किसी भी चीज़ में छोटी rounding errors introduce कर सकता है।

उदाहरण: Floating-Point Type

c
// Include standard input/output (printf, scanf)
#include <stdio.h>
// Program execution starts in main()
int main() {
	// Declare price and set it to 19.99f
	float price = 19.99f;
	// Print formatted text to the screen
	printf("%.2f", price);
	// Return 0 to signal that the program finished successfully
	return 0;
}

Double Type

double 8 bytes इस्तेमाल करता है -- float की जगह का दोगुना -- लगभग 15-16 significant digits की precision store करने के लिए, इसे decimal math के लिए C में default choice बनाते हुए जहाँ memory बचाने से ज़्यादा accuracy मायने रखती है।

उदाहरण: Double Type

c
// Include standard input/output (printf, scanf)
#include <stdio.h>
// Program execution starts in main()
int main() {
	// Declare pi and set it to 3.14159265358979
	double pi = 3.14159265358979;
	// Print formatted text to the screen
	printf("%.10f", pi);
	// Return 0 to signal that the program finished successfully
	return 0;
}

Void Type

void किसी value की absence represent करता है और सबसे ज़्यादा एक function के return type की तरह इस्तेमाल होता है यह signal देने के लिए कि function एक action perform करता है लेकिन अपने caller को कोई data वापस नहीं देता -- 0 या एक empty string return करने से अलग।

उदाहरण: Void Type

c
// Include standard input/output (printf, scanf)
#include <stdio.h>
void greet() {
	// Print formatted text to the screen
	printf("Hello from a void function");
}
// Program execution starts in main()
int main() {
	greet();
	// 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. एक int में एक decimal value store करना, जैसे int price = 9.99;, जो चुपचाप fraction drop कर देता है।
  2. double quotes के साथ char c = "A"; लिखना, जो एक string है, single character नहीं; इसकी जगह A इस्तेमाल करें।
  3. यह मान लेना कि int हमेशा 4 bytes का होता है, जब इसका size platform पर depend करता है।

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.