C++ variables code example

Example 1: declare variable c++

#include <iostream>
using namespace std;

int main(){
   	int numero; //il tipo della variabile è int, il nome della variabile è 'numero'
}

Example 2: C++ Variable

#include <iostream>
using namespace std;
int main(){
	
int number = 1;              
double decimal = 6.9;    
char characterx = 'i';   
string text ="Sup";     
bool boolean = true;      

return 0;
}

Example 3: c++ declare variable

std::string str = "text";	// stores a string
int    foo = 3;				// stores any integer
float  bar = 3.14;			// stores 32 bit number
double baz = 3.14159265;	// stores 64 bit number

Example 4: variabvles in c++

#include <iostream>

using namespace std
  
int main{
	int x = 3;
    float g = 4.0;
    long h = 1234567;
    double j = 1237886.099;
    cout<<x<<endl;
    cout<<h<<endl;
    cout<<g<<endl;
    cout<<j<<endl;
}

Example 5: C++ variables

Create a variable called myNum of type int and assign it the value 15:
  int myNum = 15;
cout << myNum;

Example 6: reference variablesr in c++

Value of i : 5
Value of i reference : 5
Value of d : 11.7
Value of d reference : 11.7