You are on page 1of 34

C++ Programming

Basic Syntax
About C++ Language
About C++ Language
Program Structure
C++ Program Structure

Comments

Preprocessor Directive

Namespace

Main function

Statments
C++ Data Types
C++ Variables
C++ Variable Definitions
C++ Keywords
C++ Keywords
C++ Operators
C++ Basic Input and Output
• When we say Input, it means to feed some data into a program. An
input can be given in the form of a file or from the command line.

• When we say Output, it means to display some data on screen,


printer, or in any file. 

• For C++ programming, we will use the iostream class

• We can only input or output data in the console screen.


C++ Basic Input and Output
• iostream class must be included.
• For input, we will use cin >>
• For output, we will use cout <<
C++ Basic Input and Output
• For input command, we will use cin >>.

• It will store data to the variable it points via >>


cin >> <variable name> ;

Example:
int num = 0;
cin >> num;  You will ask to input at the console screen.
C++ Basic Input and Output
• For input command, we will use cout <<.

• It will store data to the variable it points via <<.


cout << <variable name> ;
cout << <literal string> ;

Example:
int num = 2;
cout << num;  The value “2” from num is displayed.
cout << “hello”;  “hello” is displayed.
cout << “hi ” << “123” << “hello”;  “hi 123hello” is displayed.
C++ Conditional Statements
• If the conditional statement is TRUE, the statement inside the
conditional scope is executed, otherwise it will not execute.

• C/C++ programming language assumes any non-zero and non-null


values as true, and if it is either zero or null, then it is assumed as
false value.
C++ Conditional Statements

• If the condition is true, execute statement


code.
• If the code is false, skip the statement
code
C++ Conditional Statements
C++ If Statements
C++ If-Else Statements
C++ If-Else-If Statements
If-Else-If Statements
C++ Switch Statements
C++ Switch Statements

You might also like