C++basics - Variables constants expressions and output...

Info iconThis preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon
1 Variables, constants, expressions and output formats
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
2 The structure of a c++ program Include header files Void main( ) { Sequence of statements } # include <iostream> # include <cmath> .. Using namespace std;
Background image of page 2
3 Input/output instructions Input cin >> a; To enter a value to a variable a. Output: cout << a; To display the contents of the variable a cout << Hello .. ; To display a message on the screen.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
4 Declaring variables Variables in a program must be declared before being used and a specific data type must be assigned. Eg. integer variables declaration. int a; bool h; short int d; char y; long int f; …..etc.
Background image of page 4
5 Consider the following code to examine the size of  each data type in bytes.  # include <iostream> using namespace std; void main() { cout <<  size of int var is:  <<sizeof(int)<<endl; …… ..                   <<sizeof(bool) }
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
6 Using constants Constants are values that will not change through the 
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 15

C++basics - Variables constants expressions and output...

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online