forked from wadehuber/codeexamples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoverview.cpp
More file actions
59 lines (48 loc) · 1.21 KB
/
Copy pathoverview.cpp
File metadata and controls
59 lines (48 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include<iostream>
#include<vector>
using namespace std;
int main() {
// Initialization C++
double a = 1.2;
double b {2.3};
double c = {2.3};
int d = 3.14;
// int e = {3.14}; // Compiler error due to incompatible types
cout << "a = " << a << endl;
cout << "b = " << b << endl;
cout << "c = " << c << endl;
cout << "d = " << d << endl;
cout << endl;
// Automatic types - deduced from the initializer
auto m = 3;
auto n = 3.14;
auto o = 'x';
auto p = "Hello";
cout << "m = " << m << endl;
cout << "n = " << n << endl;
cout << "o = " << o << endl;
cout << "p = " << p << endl;
cout << endl;
// Constants
const int cint = 10;
constexpr int cexp = 20;
cout << "cint = " << cint << endl;
cout << "cexp = " << cexp << endl;
cout << endl;
// Range-for (or for-each)
vector<int> v = {1, 2, 3, 4};
cout << "v = ";
for (auto const &ii : v) {
cout << ii << " ";
}
cout << endl;
// Pointer
int * ptr = nullptr; //* Null pointer
if (ptr == nullptr) {
cout << "ptr is null (nullptr)" << endl;
}
else {
cout << "ptr is not null" << endl;
}
return 0;
}