Menu

C++ TUTORIALS - C++Variable Types

C++Variable Types

ADVERTISEMENTS

TypeDescription
boolStores either value true or false.
charTypically a single octet(one byte). This is an integer type.
intThe most natural size of integer for the machine.
floatA single-precision floating point value.
doubleA double-precision floating point value.
voidRepresents the absence of type.
wchar_tA 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;