C++ TUTORIALS - C++Variable Types
C++Variable Types
ADVERTISEMENTS
Type | Description |
---|---|
bool | Stores either value true or false. |
char | Typically a single octet(one byte). This is an integer type. |
int | The most natural size of integer for the machine. |
float | A single-precision floating point value. |
double | A double-precision floating point value. |
void | Represents the absence of type. |
wchar_t | A wide character type. |
ADVERTISEMENTS
Variable Definition in C++:
type variable_list;ADVERTISEMENTS
int i, j, k; char c, ch; float f, salary; double d;
type variable_name = value;
extern int d = 3, f = 5; // declaration of d and f. int d = 3, f = 5; // definition and initializing d and f. byte z = 22; // definition and initializes z. char x = 'x'; // the variable x has the value 'x'.Example
#include <iostream> using namespace std; // Variable declaration: extern int a, b; extern int c; extern float f; int main () { // Variable definition: int a, b; int c; float f; // actual initialization a = 10; b = 20; c = a + b; cout << c << endl ; f = 70.0/3.0; cout << f << endl ; return 0; }
30 23.3333
// function declaration int func(); int main() { // function call int i = func(); } // function definition int func() { return 0; }Lvalues and Rvalues:
int g = 20;
10 = 20;