Skip to content

Commit 3cdf006

Browse files
committed
update
1 parent 7dfb0b5 commit 3cdf006

File tree

5 files changed

+94
-4
lines changed

5 files changed

+94
-4
lines changed
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
---
2+
title: C++ data types size
3+
date: 2022-10-01 13:09:44
4+
categories:
5+
- c++
6+
tags:
7+
- c++
8+
---
9+
10+
## Result
11+
12+
```
13+
the size of bool is: 1
14+
the size of char is: 1
15+
the size of short is: 2
16+
the size of int is: 4
17+
the size of unsigned int is: 4
18+
the size of long is: 8
19+
the size of unsigned long is: 8
20+
the size of float is: 4
21+
the size of double is: 8
22+
the size of long int is: 8
23+
the size of long long is: 8
24+
the size of long double is: 8
25+
the max of short is 32767
26+
the min of short is -32768
27+
the max of int is 2147483647
28+
the min of int is -2147483648
29+
the max of unsigned int is 4294967295
30+
the min of unsigned int is 0
31+
the max of long is 9223372036854775807
32+
the min of long is -9223372036854775808
33+
the max of unsigned long is 18446744073709551615
34+
the min of unsigned long is 0
35+
the max of long long is 9223372036854775807
36+
the min of long long is -9223372036854775808
37+
```
38+
39+
## Code
40+
41+
``` c++
42+
#include <iostream>
43+
#include <limits>
44+
45+
int main() {
46+
bool a;
47+
char b;
48+
short c;
49+
int d;
50+
unsigned int e;
51+
long f;
52+
unsigned long g;
53+
float h;
54+
double i;
55+
long int j; // this is the same as long
56+
long long k; // for linux x64 long and long long are both 8 bytes
57+
long double l;
58+
59+
std::cout << "the size of bool is: " << sizeof(a) << "\n";
60+
std::cout << "the size of char is: " << sizeof(b) << "\n";
61+
std::cout << "the size of short is: " << sizeof(c) << "\n";
62+
std::cout << "the size of int is: " << sizeof(d) << "\n";
63+
std::cout << "the size of unsigned int is: " << sizeof(e) << "\n";
64+
std::cout << "the size of long is: " << sizeof(f) << "\n";
65+
std::cout << "the size of unsigned long is: " << sizeof(g) << "\n";
66+
std::cout << "the size of float is: " << sizeof(h) << "\n";
67+
std::cout << "the size of double is: " << sizeof(i) << "\n";
68+
std::cout << "the size of long int is: " << sizeof(j) << "\n";
69+
std::cout << "the size of long long is: " << sizeof(k) << "\n";
70+
std::cout << "the size of long double is: " << sizeof(l) << "\n";
71+
72+
std::cout << "the max of short is " << std::numeric_limits<short>::max() << "\n";
73+
std::cout << "the min of short is " << std::numeric_limits<short>::min() << "\n";
74+
75+
std::cout << "the max of int is " << std::numeric_limits<int>::max() << "\n";
76+
std::cout << "the min of int is " << std::numeric_limits<int>::min() << "\n";
77+
78+
std::cout << "the max of unsigned int is " << std::numeric_limits<unsigned int>::max() << "\n";
79+
std::cout << "the min of unsigned int is " << std::numeric_limits<unsigned int>::min() << "\n";
80+
81+
std::cout << "the max of long is " << std::numeric_limits<long>::max() << "\n";
82+
std::cout << "the min of long is " << std::numeric_limits<long>::min() << "\n";
83+
84+
std::cout << "the max of unsigned long is " << std::numeric_limits<unsigned long>::max() << "\n";
85+
std::cout << "the min of unsigned long is " << std::numeric_limits<unsigned long>::min() << "\n";
86+
87+
std::cout << "the max of long long is " << std::numeric_limits<long long>::max() << "\n";
88+
std::cout << "the min of long long is " << std::numeric_limits<long long>::min() << "\n";
89+
}
90+
```

source/_posts/Backend/c++/C-generate-random-number.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: C++ generate random number
33
date: 2022-09-14 12:27:50
44
categories:
5-
- Backend
5+
- c++
66
tags:
77
- c++
88
---

source/_posts/Backend/c++/Connect-different-classes-in-C.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: Connect different classes in C++
33
date: 2022-02-19 18:04:57
44
categories:
5-
- Backend
5+
- c++
66
tags:
77
- c++
88
---

source/_posts/Backend/c++/c-多层Switch简化.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: c++多层Switch简化
33
date: 2022-02-10 18:07:40
44
categories:
5-
- Backend
5+
- c++
66
tags:
77
- c++
88
---

source/_posts/Backend/c++/lambda-expression-in-C.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: lambda expression in C++
33
date: 2022-02-26 16:22:27
44
categories:
5-
- Backend
5+
- c++
66
tags:
77
- c++
88
---

0 commit comments

Comments
 (0)