Variables in C++ code example
Example 1: declare variable c++
#include <iostream>
using namespace std;
int main(){
int numero;
}
Example 2: c++ declare variable
std::string str = "text";
int foo = 3;
float bar = 3.14;
double baz = 3.14159265;
Example 3: 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 4: C++ variables
Create a variable called myNum of type int and assign it the value 15:
int myNum = 15;
cout << myNum;
Example 5: constant variables in c++
#include <iostream>
class Entity {
private:
int m_X, m_Y;
mutable int var;
int* m_x, *m_y;
public:
int GetX() const
{
var = 5;
return m_X;
}
int Get_X()
{
return m_X;
}
const int* const getX() const
{
return m_x;
}
void PrintEntity(const Entity& e) {
std::cout << e.GetX() << std::endl;
}
};
int main() {
Entity e;
const int MAX_AGE = 90;
int * const a = new int;
*a = 2;
a = &MAX_AGE;
std::cout << *a << std::endl;
a =(int*) &MAX_AGE;
std::cout << *a << std::endl;
}
Example 6: 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;
}