C provides a range of data types to store different kinds of data such as numbers, characters, and floating-point values.
The four primary data types are int
, float
, char
, and double
.
C में कई तरह के data types होते हैं जिनमें number, character और decimal values रखी जाती हैं।
चार main data types हैं int
, float
, char
, और double
।
#include <stdio.h>
int main() {
int number = 100;
printf("Integer value: %d", number);
return 0;
}
Explanation (English): int is used to declare integer variables without decimal points.
Explanation (Hinglish): int का उपयोग integer variables (बिना decimal) रखने के लिए किया जाता है।
Output: Integer value: 100
#include <stdio.h>
int main() {
float price = 10.75;
printf("Float value: %.2f", price);
return 0;
}
Explanation (English): float holds decimal values with 6-digit precision.
Explanation (Hinglish): float decimal values (लगभग 6-digit precision) रखने के लिए use होता है।
Output: Float value: 10.75
#include <stdio.h>
int main() {
double pi = 3.1415926535;
printf("Double value: %.10lf", pi);
return 0;
}
Explanation (English): double holds more precise decimal values than float.
Explanation (Hinglish): double float से ज्यादा precise decimal values रखता है।
Output: Double value: 3.1415926535
#include <stdio.h>
int main() {
char letter = 'C';
printf("Character: %c", letter);
return 0;
}
Explanation (English): char stores a single character enclosed in single quotes.
Explanation (Hinglish): char एक single character को single quotes में store करता है।
Output: Character: C
#include <stdio.h>
int main() {
int a;
printf("Size of int: %zu bytes", sizeof(a));
return 0;
}
Explanation (English): sizeof returns the memory size (in bytes) of the variable.
Explanation (Hinglish): sizeof किसी variable का memory size (bytes में) return करता है।
Output: Size of int: 4 bytes (may vary)
#include <stdio.h>
int main() {
short s = 10;
long l = 123456789L;
printf("Short: %d, Long: %ld", s, l);
return 0;
}
Explanation (English): short and long are used to alter the size of integer data.
Explanation (Hinglish): short और long integer data के size को बदलने के लिए use होते हैं।
Output: Short: 10, Long: 123456789
#include <stdio.h>
int main() {
unsigned int u = 4294967295;
printf("Unsigned: %u", u);
return 0;
}
Explanation (English): unsigned int cannot store negative numbers, but allows a larger range of positive values.
Explanation (Hinglish): unsigned int negative numbers नहीं रख सकता, पर ज्यादा बड़े positive values रख सकता है।
Output: Unsigned: 4294967295
#include <stdio.h>
enum Day { SUN, MON, TUE, WED };
int main() {
enum Day today = MON;
printf("Day: %d", today);
return 0;
}
Explanation (English): enum assigns readable names to integer values, starting from 0.
Explanation (Hinglish): enum readable names assign करता है integer values को (शुरुआत 0 से)।
Output: Day: 1
#include <stdio.h>
void greet() {
printf("Hello from void function!");
}
int main() {
greet();
return 0;
}
Explanation (English): void indicates the function does not return a value.
Explanation (Hinglish): void बताता है कि function कोई value return नहीं करता।
Output: Hello from void function!
#include <stdio.h>
int main() {
int a = 5, b = 2;
float result = (float)a / b;
printf("Result: %.2f", result);
return 0;
}
Explanation (English): Casting with (float) allows decimal output instead of integer division.
Explanation (Hinglish): (float) casting से integer division की बजाय decimal result मिलता है।
Output: Result: 2.50