Return to Topic Menu | Computer Science Main Page | MathBits.com | Terms of Use

Printing Variables

The cout statement may be used to print the information stored in any variable location to the screen.
It is possible to intermix several types of variables into one
cout statement as seen below:

int num1 = 4;
double num2 = 6.5;
cout << num1 << " and also " << num2 << endl;

or for easier reading:

cout << num1
        << " and also "
        << num2
        << endl;



Numbers and/or computations may also be printed without variable names:

cout << 976;   // prints 976 on screen


cout << 3*5*2+10;  // prints 40 on screen

Return to Topic Menu | Computer Science Main Page | MathBits.com  | Terms of Use