C के Data Types
In this page:
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
// 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;
}
Login to try C/C++/Java/PHP code in the editor
Character Type
char exactly 1 byte में एक single character store करता है, लेकिन internally यह असल में सिर्फ एक छोटा integer है जो ASCII table में उस character की position represent करता है -- यही वजह है कि आप C में char values पर सीधे arithmetic कर सकते हैं।
उदाहरण: Character Type
// 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;
}
Login to try C/C++/Java/PHP code in the editor
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
// 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;
}
Login to try C/C++/Java/PHP code in the editor
Double Type
double 8 bytes इस्तेमाल करता है -- float की जगह का दोगुना -- लगभग 15-16 significant digits की precision store करने के लिए, इसे decimal math के लिए C में default choice बनाते हुए जहाँ memory बचाने से ज़्यादा accuracy मायने रखती है।
उदाहरण: Double Type
// 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;
}
Login to try C/C++/Java/PHP code in the editor
Void Type
void किसी value की absence represent करता है और सबसे ज़्यादा एक function के return type की तरह इस्तेमाल होता है यह signal देने के लिए कि function एक action perform करता है लेकिन अपने caller को कोई data वापस नहीं देता -- 0 या एक empty string return करने से अलग।
उदाहरण: Void Type
// 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;
}
Login to try C/C++/Java/PHP code in the editor
- एक
intमें एक decimal value store करना, जैसेint price = 9.99;, जो चुपचाप fraction drop कर देता है। - double quotes के साथ
char c = "A";लिखना, जो एक string है, single character नहीं; इसकी जगहAइस्तेमाल करें। - यह मान लेना कि
intहमेशा 4 bytes का होता है, जब इसका size platform पर depend करता है।
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