How To Declare Variables In C++?

How To Declare Variables In C++? 

Assigning the name and data type that a variable can hold is called declaration of variable. All variables that are used in a program are declared using variable declaration statement.

The syntax to declare variable in C++ is:

type list of variables;

where

type               

specifies data types of variables.

list of variables

specifies a list of variables separated by commas.

To declare variables and xy as input type, b as float type, nm as string type of 15 characters and sum as double, the statements are written as

int a, xy;
float b;
char nm [15];
double sum;


Note:  To print the contents stored in a variable, the variable name is given in the output ( i.e cout) statement without quotes.
Creative Commons License
Pakistan How by Tahira Aijaz is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.