0% found this document useful (0 votes)
3 views

Chapter 1 Review of C++ Programming

Plus two computer application

Uploaded by

jipam72524
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Chapter 1 Review of C++ Programming

Plus two computer application

Uploaded by

jipam72524
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

Chapter 1

Review of C++ Programming


What are Statements in a C++
Program?
Statements are fragments of C++ program that are executed in sequence

There are four kinds of statements in C++ program. They are:
1)Declaration statement: Used to declare identifiers before their
usage. Eg: int a, b, sum; Values can be provided to the
variables along with the declaration. This kind of statement is
known as variable initialisation statement. Eg: float pi = 3.14;
2)Output statement: Used to perform output operation. Eg:
cout<<“Hello world”; Here cout is a pre-defined identifier and
<< is an insertion operator or put to operator.
3)Assignment statement: Used to store a data in a memory
location. Eg: n=253; Here = is called Assignment operator.
4)Input statement: Used to perform input operation. Eg: cin >> a
>> b; Here cin is a predefined identifier and >> is an extraction
operator or get from operator.
Arithmetic Assignment Operators


A simple arithmetic statement can be expressed
in a more condensed form using arithmetic
assignment operators.

For example, a=a+10 can be represented as
a+=10.

Here += is an arithmetic assignment operator.

The arithmetic assignment operators in C++ are
+=, -=, *=, /=, %=
What is Increment Operator ?


The increment operator is represented by ++ symbol.

It is a unary operator.

It adds 1 to the content of the operand variable and the result is
stored in it.

There are two forms of increment operator;
1)Prefix form (change and use method.): In Prefix form, the
value of the variable in increased by 1 immediately. Eg: ++a

2)Postfix form (use and change method.) : In Postfix form, the


value of the variable is increased only in the next statement. Eg:
a++
What is Decrement Operator ?


The decrement operator is represented by -- symbol.

It is a unary operator.

It subtracts 1 from the content of the operand
variable and the result is stored in it

There are two forms of decrement operator;
1)Prefix form In Prefix form, the value of the variable in decreased by 1 immediately.

2)Postfix form In Postfix form, the value of the variable is decreased only in the
next statement.
What is Cascading?


The input, output and assignment operators
(>>, << and =) may appear more than once in
the respective statements. It is known as
cascading.

Eg:

cin >> a >> b >> c;

cout << "Sum of " << n << "numbers = " << sum;

a = b = c;
What are Jump Statements?


Jump statements are used to jump unconditionally to a
different statement. It is used to alter the flow of control
unconditionally.

There are three types of jump statements in C++
a)Break: break statement is used to terminate a loop or switch
statement.
b)Continue: continue statement is used to continue to the
beginning of a loop. When a continue statement is executed
in a loop it skips the remaining statements in the loop and
proceeds with the next iteration of the loop.
c)Goto: goto statement is used for unconditional jump. It
transfers the control from one part of the program to another
What are tokens?


Tokens are the basic building blocks of a C++ program.

There are five types of tokens in C++.
1)Keywords: Keywords are tokens that carry a specific meaning to the language
compiler. Eg. int, switch etc..
2)Identifiers: Identifiers are user defined words that are used to name different
program elements such as memory locations, statements, functions, classes etc.
Identifiers used for naming memory location is known as variables. Identifiers
assigned to statements are known as labels. Identifiers used for set of statements
are known as functions.
3)Literal : Literals are data items that never change their values during the program
running. They are also known as constants. There are 4 types of literals: Integer
Literal, Floating Point Literal, Character Literal, String Literal
4)Punctuators: Special symbols that have syntactic or semantic meaning to the
compiler. Eg: #,:,’,”,() ,[]
5)Operators: Operators are the tokens that trigger some kind of operations. The
operations applied on a set of data called operands. Eg: +, - , * , /
What are Data Types?


These are means to identify the type of data
and associated operations handling these data.

Data types are classified into fundamental and
user-defined data types.

Fundamental data types represent atomic
values and they include int, char, float, double
and void.
What are type modifiers?


Type modifiers are used to modify the size of
memory space and range of data supported by
the basic data types.

Eg. long, short, signed, unsigned
What are expressions?


Expressions are constituted by operators and operands to perform an
operation. Based on the operators used, there are different types of
expressions like ,

i). Arithmetic expressions: Arithmetic expressions are also divided into

a). Integer expression :All operands in the expressions are integers.


An integer expression yields an integer result. Eg: a+b

b). Floating point (decimal ) expression: All operands in the


expression are floating points(decimals).A floating point expression
yields a floating point result. Eg: a+b

ii). Relational expression : It consists of numeric or character data as
operands and they return true or false as outputs. Eg: a>b

iii). Logical expression : It uses relational expressions as operands
and return true or false as results. Eg: a>b && a>c
What is type conversion?


Type conversion means converting one data type to another
data type.

There are two types of type conversion:
1)Implicit type conversion (Type Promotion): also known as
automatic type conversion is performed by the compiler. The
conversion is always from lower type to higher type.
Eg: 6+2.5=8.5
2)Explicit type conversion (Type casting): refers to conversion
that is performed explicitly using cast operator. The operator
used for this purpose is known as cast operator. The cast
operator takes on the format cast type (expression)

eg int a = (int) 10.5 , Here the value 10.5 is converted to integer
type
Previous Questions


1. Which among the following is an insertion operator ?
(a) << (b) >> (c) < (d) >

2.What are the main components of a looping statement
?

3. How do continue and break statement differ in a
loop ?

4. …………… is an exit control loop.
a)for loop b)while loop c)do …while loop d)break

5.Explain switch statement with an example.

6.Compare continue and break statement ?

7. Compare the selection statements ‘if’ and
switch

8. Define Jump statements. Explain any two.

9. Explain about nested loops

10. The input operator in C++ is ........

11. List the type modifiers in C++

You might also like