C++ provides various data types to store different kinds of data like numbers, characters, and floating-point values.
Common C++ data types include int
, float
, char
, double
, and bool
.
C++ में कई तरह के data types होते हैं जैसे number, character और decimal values रखने के लिए।
कुछ common C++ data types हैं int
, float
, char
, double
, और bool
.
#include <iostream>
using namespace std;
int main() {
int number = 100;
cout << "Integer value: " << number << endl;
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 <iostream>
using namespace std;
int main() {
float price = 10.75;
cout << "Float value: " << price << endl;
return 0;
}
Explanation (English): float holds decimal values with about 6-digit precision.
Explanation (Hinglish): float decimal values (लगभग 6-digit precision) रखने के लिए use होता है।
Output: Float value: 10.75
#include <iostream>
using namespace std;
int main() {
double pi = 3.1415926535;
cout << "Double value: " << pi << endl;
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 <iostream>
using namespace std;
int main() {
char letter = 'C';
cout << "Character: " << letter << endl;
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 <iostream>
using namespace std;
int main() {
bool isOpen = true;
cout << "Is Open: " << isOpen << endl;
return 0;
}
Explanation (English): bool represents true or false values.
Explanation (Hinglish): bool true या false value को दर्शाता है।
Output: Is Open: 1
#include <iostream>
using namespace std;
int main() {
int a;
cout << "Size of int: " << sizeof(a) << " bytes" << endl;
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 <iostream>
using namespace std;
int main() {
short s = 10;
long l = 123456789L;
cout << "Short: " << s << ", Long: " << l << endl;
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 <iostream>
using namespace std;
int main() {
unsigned int u = 4294967295;
cout << "Unsigned: " << u << endl;
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 <iostream>
using namespace std;
enum Day { SUN, MON, TUE, WED };
int main() {
Day today = MON;
cout << "Day: " << today << endl;
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 <iostream>
using namespace std;
int main() {
int a = 5, b = 2;
float result = (float)a / b;
cout << "Result: " << result << endl;
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.5