C++ Variable
In C++, variables are used to store data that can be used and manipulated throughout a program. Understanding how to declare, initialize, and use variables is fundamental to programming in C++. Here is an overview of variables in C++.
Variable Declaration
In C++, variables must be declared before they are used. A variable declaration specifies the type of data that the variable will hold and the name of the variable.
Syntax:
type variable_name;
int age;
float salary;
char grade;
Variable Types
C++ supports various data types, including:
- Basic Types:
int
,float
,double
,char
,bool
- Derived Types: Arrays, pointers, references
- User-Defined Types: Classes, structures, enumerations