Declare and Assign Values to Variables in C++

Declare and Assign Values to Variables in C++:

(1) In this blog, we will see how to declare and assign values to variables.

  • int myInt = 10;
  • double myDouble = 10.5;
  • char myChar = ‘A’;
  • string myString = “My first String”;
  • bool myBool = True;

(2) Sample C++ language code and its output, as shown:

Declare and Assign Values to Variables in C++ sample code
#include <iostream>
using namespace std;
int main()
  //Declare int variable
intmyfirstinteger = 10;
cout<< “Integer Variable Value:” <<myfirstinteger<< “\n”;
  //Declare double variable
doublemyfirstdouble = 10.5;
cout<< “Double Variable Value:” <<myfirstdouble<< “\n”;
  //Declare char variable
charmyfirstchar = ‘A’;
cout<< “Char Variable Value:” <<myfirstchar<< “\n”;
  //Declare bool variable
boolmyfirstbool = true;
cout<< “Bool Variable Value:” <<myfirstbool<< “\n”;
  //Declare string variable
stringmyfirststring = “My First String”;
cout<< “String Variable Value:” <<myfirststring<< “\n”;
return 0;

(3) After that go to the “Build” menu and select the “Build” option for publishing the code as shown.

click on build for c++ variables code

(4) After building the code, press the “Run” button, as shown.

run the code for c++ varibale

(5) After pressing the “run” button, the output screen is opened, as shown.

Output screen shown c++ variables

How to Create New Database in Microsoft SQL Server
How to Attach MDF file Without LDF File by using SSMS
How to Install SQL Management Studio
How to Select Records from Table via SQL using SELECT Statement
SELECT statement (Microsoft Access SQL)– Microsoft Docs

Leave a Reply