1std::string str = "text"; // stores a string
2int foo = 3; // stores any integer
3float bar = 3.14; // stores 32 bit number
4double baz = 3.14159265; // stores 64 bit number
1#include <iostream>
2using namespace std;
3int main(){
4
5int number = 1;
6double decimal = 6.9;
7char characterx = 'i';
8string text ="Sup";
9bool boolean = true;
10
11return 0;
12}
1#include <iostream>
2
3using namespace std
4
5int main{
6 int x = 3;
7 float g = 4.0;
8 long h = 1234567;
9 double j = 1237886.099;
10 cout<<x<<endl;
11 cout<<h<<endl;
12 cout<<g<<endl;
13 cout<<j<<endl;
14}
1Create a variable called myNum of type int and assign it the value 15:
2 int myNum = 15;
3cout << myNum;
1#include <iostream>
2using namespace std;
3
4int main() {
5// To define variables in C++, you have to specify the data type. Example:
6int number = 10; // Declares a variable with the integer data type.
7float decimal = 3.5; // Declares a variable with the float data type.
8double decimalNum = 3.3333; // Doubles are used for more specific points in floats.
9string text = "Hello World"; // Declares a variable with the string data type.
10bool result = true; // Declares a variable with the boolean data type.
11
12}