0% found this document useful (0 votes)
7 views23 pages

4.programming Language Concepts (Lecture-4) 566 5

Uploaded by

Musawer Afzali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views23 pages

4.programming Language Concepts (Lecture-4) 566 5

Uploaded by

Musawer Afzali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

C++ Building Blocks

(Lecture-4)

1
Contents
• C++ comments

• Types of C++ comments

• Keywords

• Constants

• Types of constants

• Instructions

• Types of instructions

• C++ input and output

• C++ expressions

2
C++ Comments

• The C++ comments are statements that are not executed by the compiler. The comments in
C++ programming can be used to provide explanation of the code, variable, method or class.
By the help of comments, you can hide the program code also.

3
Types of C++ Comments

• There are two types of comments in C++.

• Single Line comment

• Multi Line comment

4
Types of C++ Comments

• C++ Single Line Comment

• The single line comment starts with // (double slash). Let's see an example of single line

comment in C++.

Output

5
Types of C++ Comments
• C++ Multi Line Comment

• The C++ multi line comment is used to comment multiple lines of code. It is surrounded by

slash and asterisk (/∗ ..... ∗/). Let's see an example of multi line comment in C++.

6
C++ Keywords

• A keyword is a reserved word. You cannot use it as a variable name, constant name etc. A

list of Keywords in C++ Language which are also available in C language are given below.

auto break case char const continue default do

double else enum extern float for goto if

int long register return short signed sizeof static

struct switch typedef union unsigned void volatile while

7
C++ statements

• A simple C++ statement is each of the individual instructions of a program, like the variable
declarations and expressions seen in previous sections. They always end with a semicolon ( ; ),
and are executed in the same order in which they appear in a program.

8
Constant

• A constant is a value or variable that can't be changed in the program, for example: 10, 20, 'a',
3.4, in programming etc.

9
Constant

• If you try to change the the value of PI, it will render compile time error.

10
Constant
Integer Constant:

• As the name itself suggests, an integer constant is an integer with a fixed value, that is, it
cannot have fractional value like 10, -8, 2019.
• For example
• const int a=10;

11
Constant
• Floating or Real Constants

• We use a floating-point constant to represent all the real numbers on the number line, which
includes all fractional values.

• const float PI= 3.14159;

12
Constant
• Character Constants

• Character constants are used to assign a fixed value to characters including alphabets and
digits or special symbols enclosed within single quotation marks( ‘ ’ ).

• Each character is associated with its specific numerical value called the ASCII (American
Standard Code For Information Interchange) value.
• For example,
const char a= ‘+’;

13
Constant
• String Constants

• A string constant is an array of characters that has a fixed value enclosed within double
quotation marks ( “ “ ).
• For example
• const string msg=“Hello World”;

14
Instruction

• Computer instructions are a set of machine language instructions that a particular processor
understands and executes. A computer performs tasks on the basis of the instruction provided.

• Basically we have 4 types of instructions

• Type Declaration Instructions

• Input/output Instructions

• Arithmetic Instructions

• Control Instruction

15
Instruction

Type Declaration Instructions

• In the Type Declaration generally variables are declared

• EX:

• int a =10;

• float pi=3.1415;

• char z=‘A’;

16
Instruction

Input/output Instructions
• In Input and output instructions we perform input data to the program and also obtaining the
output Results from it.

• EX:

int a;
cin>>a;
cout<<a;

17
Instruction

Arithmetic Instructions
• Arithmetic instructions are used for performing the Arithmetic operations like addition,
subtraction and Multiplication [Link]:

Int x=20,y=30,sum,mul;

sum=x+y;

Mul=x*y;

18
Instruction

Control Instruction
• Control Instructions are used to control the sequence of execution of various statements in
program.

• EX:

for(int a=0;a<20;a++){

cout<<“Afghanistan”;

19
C++ Basic Input/Output
• C++ I/O operation is using the stream concept. Stream is the sequence of bytes or flow of data.

• If bytes flow from main memory to device like printer, display screen, or a network connection, etc, this is
called as output operation.

• If bytes flow from device like Scanner, Microphone, or a network connection, etc to main memory, this is
called as input operation.

20
C++ Basic Input/Output
• Standard output stream (cout)
The cout is a predefined object of ostream class. It is connected with the standard output device,
which is usually a display screen. The cout is used in conjunction with stream insertion operator (<<) to
display the output on a console

1.#include <iostream>
[Link] namespace std;
[Link] main( ) {
4. int a = 100;
5. cout << "Value of A is: " << a << endl;
6.}

21
C++ Basic Input/Output
Standard input stream (cin)

The cin is a predefined object of istream class. It is connected with the standard input
device, which is usually a keyboard. The cin is used in conjunction with stream extraction
operator (>>) to read the input from a console.
1.#include <iostream>
[Link] namespace std;
[Link] main( ) {
4. int age;
5. cout << "Enter your age: ";
6. cin >> age;
7. cout << "Your age is: " << age << endl;
8.}

22
Thank You…!

You might also like