0% found this document useful (0 votes)
9 views37 pages

C++ 1

The document provides an overview of programming concepts, focusing on the differences between Procedure Oriented Programming and Object Oriented Programming (OOP). It explains key OOP concepts such as classes, objects, encapsulation, abstraction, polymorphism, inheritance, dynamic binding, and message passing, highlighting the benefits of OOP like code reusability and data security. Additionally, it introduces C++ as an object-oriented programming language that extends C with features like classes and operator overloading.

Uploaded by

kowsalyaproj
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)
9 views37 pages

C++ 1

The document provides an overview of programming concepts, focusing on the differences between Procedure Oriented Programming and Object Oriented Programming (OOP). It explains key OOP concepts such as classes, objects, encapsulation, abstraction, polymorphism, inheritance, dynamic binding, and message passing, highlighting the benefits of OOP like code reusability and data security. Additionally, it introduces C++ as an object-oriented programming language that extends C with features like classes and operator overloading.

Uploaded by

kowsalyaproj
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
You are on page 1/ 37

OPEN ELECTIVE

PAPER - 3
B.PROGRAMMING USING C++
UNIT – I: BASIC CONCEPTS
A look at Procedure Oriented Programming – Object Oriented Programming Paradigm – Basic
Concepts of Object Oriented Programming – Benefits of OOP – Object Oriented Languages –
Beginning With C++ - A Simple C++ Program – Structure of C++ Program – Tokens – Basic
Data Types – Scope Resolution Operator – Manipulators – Expressions – Control Structures.

1.1 A look at Procedure Oriented Programming

➢ Programming in the high-level languages such as COBOL, FORTRAN, C, etc. is known


as procedure-oriented programming.
➢ Procedure-oriented programming basically contains group of instructions known as
function. There are multiple functions into the program.
➢ In below figure we have divided our program into multiple functions.
➢ We use flowchart or algorithm to show how the program is executed from one instruction
to other instruction.
➢ It doesn’t emphasize on the data.

A.PRAKASH (GL), COMPUTER SCIENCE DEPARTMENT, ARIGNAR ANNA GOVERNMENT ARTS COLLEGE , CHEYYAR.
Page 1
➢ In a multi-function program we use global variable to communicate between two functions.

➢ Global variable can be use by any function at any time while local variables are only used within
the function.
➢ But it creates problem in large program because we can’t determine which global variables (data)
are used by which function.
➢ Also global variables are accessed by all the function so any function can change its value at any
time so all the function will be affected.

Characteristics of procedure-oriented programming language

1. It emphasis on algorithm (doing this ).


2. Large programs are divided into smaller programs known as functions.
3. Function can communicate by global variable.
4. Data move freely from one function to another function.
5. Functions change the value of data at any time from any place. (Functions transform data
from one form to another.)
6. It uses top-down programming approach.

1.2Object Oriented Programming Paradigm

• The major motivating factor in the invention of object-oriented approch is to remove


some of the flaws encountered in the procedural approch.
• OOP treats data as a critical element in the program development and does not allow it to
flow freely around the systems.
• It ties data more closely to the functions that operate on it, and protects it from accidental
modification from outside functions.
A.PRAKASH (GL), COMPUTER SCIENCE DEPARTMENT, ARIGNAR ANNA GOVERNMENT ARTS COLLEGE , CHEYYAR.
Page 2
• OOP allows decomposition of a problem into a number of entities called objects and then
builds data and functions around these objects.
• The data of an object can be accessed only by the function associated with that object.
• However, functions of one object can access the the functions of other objects.

Some of the striking features of object-oriented programming are

• Emphasis is on data rather than procedure.


• Programs are divided into what are known as objects.
• Data structures are designed such that they characterize the objects.
• Data is hidden and cannot be accessed by external functions.
• Objects may communicate with each other through functions.
• New data and functions can be easily added whenever necessary.
• Follows bottom-up approch in program design.

1.3 Basic Concepts of Object Oriented Programming

➢ Introduction
➢ Class
➢ Objects
➢ Encapsulation
➢ Abstraction
➢ Polymorphism
➢ Inheritance
➢ Dynamic Binding
➢ Message Passing

A.PRAKASH (GL), COMPUTER SCIENCE DEPARTMENT, ARIGNAR ANNA GOVERNMENT ARTS COLLEGE , CHEYYAR.
Page 3
➢ Introduction
Object-oriented programming – As the name suggests uses objects in programming.
Object-oriented programming aims to implement real-world entities like inheritance, hiding,
polymorphism, etc in programming. The main aim of OOP is to bind together the data and the
functions that operate on them so that no other part of the code can access this data except that
function.
➢ Class
The building block of C++ that leads to Object-Oriented programming is a Class. It is a
user-defined data type, which holds its own data members and member functions, which can be
accessed and used by creating an instance of that class. A class is like a blueprint for an object.

For Example: Consider the Class of Cars. There may be many cars with different names and
brand but all of them will share some common properties like all of them will have 4 wheels,
Speed Limit, Mileage range etc. So here, Car is the class and wheels, speed limits, mileage are
their properties.
• A Class is a user-defined data-type which has data members and member functions.
• Data members are the data variables and member functions are the functions used to
manipulate these variables and together these data members and member functions define
the properties and behaviour of the objects in a Class.
• In the above example of class Car, the data member will be speed limit, mileage etc and
member functions can apply brakes, increase speed etc.
We can say that a Class in C++ is a blue-print representing a group of objects which shares
some common properties and behaviours.

➢ Object

An Object is an identifiable entity with some characteristics and behaviour. An Object is an


instance of a Class. When a class is defined, no memory is allocated but when it is instantiated
(i.e. an object is created) memory is allocated.

A.PRAKASH (GL), COMPUTER SCIENCE DEPARTMENT, ARIGNAR ANNA GOVERNMENT ARTS COLLEGE , CHEYYAR.
Page 4
class person
{
char name[20];
int id;
public:
void getdetails(){}
};
int main()
{
person p1; // p1 is a object

• Object take up space in memory and have an associated address like a record in pascal or
structure or union in C.
• When a program is executed the objects interact by sending messages to one another
• Each object contains data and code to manipulate the data. Objects can interact without
having to know details of each other’s data or code, it is sufficient to know the type of
message accepted and type of response returned by the objects.
➢ Encapsulation

In normal terms, Encapsulation is defined as wrapping up of data and information under a


single unit. In Object-Oriented Programming, Encapsulation is defined as binding together the
data and the functions that manipulate them.

• Consider a real-life example of encapsulation, in a company, there are different sections


like the accounts section, finance section, sales section etc. The finance section handles all the
financial transactions and keeps records of all the data related to finance. Similarly, the sales
section handles all the sales-related activities and keeps records of all the sales. Now there may
arise a situation when for some reason an official from the finance section needs all the data
about sales in a particular month. In this case, he is not allowed to directly access the data of
the sales section. He will first have to contact some other officer in the sales section and then
request him to give the particular data. This is what encapsulation is. Here the data of the sales
section and the employees that can manipulate them are wrapped under a single name “sales
section”.

A.PRAKASH (GL), COMPUTER SCIENCE DEPARTMENT, ARIGNAR ANNA GOVERNMENT ARTS COLLEGE , CHEYYAR.
Page 5
• Encapsulation also leads to data abstraction or hiding. As using encapsulation also hides
the data. In the above example, the data of any of the section like sales,finance or accounts
are hidden from any other section.
➢ Abstraction
Data abstraction is one of the most essential and important features of object-
oriented programming in C++. Abstraction means displaying only essential information
and hiding the details. Data abstraction refers to providing only essential information about
the data to the outside world, hiding the background details or implementation.

Consider a real-life example of a man driving a car. The man only knows that pressing
the accelerators will increase the speed of the car or applying brakes will stop the car but he
does not know about how on pressing accelerator the speed is actually increasing, he does not
know about the inner mechanism of the car or the implementation of accelerator, brakes etc in
the car. This is what abstraction is.
• Abstraction using Classes: We can implement Abstraction in C++ using classes. The class
helps us to group data members and member functions using available access specifiers. A
Class can decide which data member will be visible to the outside world and which is not.

• Abstraction in Header files: One more type of abstraction in C++ can be header files. For
example, consider the pow() method present in math.h header file. Whenever we need to
calculate the power of a number, we simply call the function pow() present in the math.h
header file and pass the numbers as arguments without knowing the underlying algorithm
according to which the function is actually calculating the power of numbers.

➢ Polymorphism:
The word polymorphism means having many forms. In simple words, we can
define polymorphism as the ability of a message to be displayed in more than one form.

A person at the same time can have different characteristic. Like a man at the same time is
a father, a husband, an employee. So the same person posses different behaviour in different
situations. This is called polymorphism.

An operation may exhibit different behaviours in different instances. The behaviour


depends upon the types of data used in the operation
C++ supports operator overloading and function overloading:
• Operator Overloading: The process of making an operator to exhibit different behaviours
in different instances is known as operator overloading.
• Function Overloading: Function overloading is using a single function name to perform
different types of tasks. Polymorphism is extensively used in implementing inheritance.

Example: Suppose we have to write a function to add some integers, some times there are 2
integers, some times there are 3 integers. We can write the Addition Method with the same

A.PRAKASH (GL), COMPUTER SCIENCE DEPARTMENT, ARIGNAR ANNA GOVERNMENT ARTS COLLEGE , CHEYYAR.
Page 6
name having different parameters, the concerned method will be called according to
parameters.

➢ Inheritance:
The capability of a class to derive properties and characteristics from another class is
called Inheritance. Inheritance is one of the most important features of Object-Oriented
Programming.

• Sub Class: The class that inherits properties from another class is called Sub class or Derived
Class.
• Super Class: The class whose properties are inherited by sub class is called Base Class or
Super class.
• Reusability: Inheritance supports the concept of “reusability”, i.e. when we want to create a
new class and there is already a class that includes some of the code that we want, we can
derive our new class from the existing class. By doing this, we are reusing the fields and
methods of the existing class.

Example: Dog, Cat, Cow can be Derived Class of Animal Base Class.

A.PRAKASH (GL), COMPUTER SCIENCE DEPARTMENT, ARIGNAR ANNA GOVERNMENT ARTS COLLEGE , CHEYYAR.
Page 7
Dynamic Binding:
In dynamic binding, the code to be executed in response to function call is decided at
runtime. C++ has virtual functions to support this.

Message Passing:

Objects communicate with one another by sending and receiving information to


each other. A message for an object is a request for execution of a procedure and therefore will
invoke a function in the receiving object that generates the desired results. Message passing
involves specifying the name of the object, the name of the function and the information to be
sent.

1.4 Benefits of OOP


OOP offers several benefits to the program designer and the user. Object-orientation
contributes to the solutions of many problem associated with the development and quality of
software products. The new technology promises greater programmer productivity, better quality
of software and lesser maintenance cost. The principal advantages are:

• Through inheritance, we can eliminate redundant code and extend the use of existing classes.
• We can built programs from standard working modules that communicate with one another
rather than, having to start writing the code from scratch. This leads to saving of
development time and higher productivity.
• The principle of data hiding helps the programmers to built secure program that can’t be
invaded by code in other parts of the program.
• It is possible to have multiple objects to coexist without any interference.
• It is possible to map objects in the problem domain to those objects in the program.
• It is easy to partition the work in a project based on objects.
• The data-centered design approach enables us to capture more details of the model in an
implementable form.
• Object-oriented systems can be easily upgraded from small to large system
A.PRAKASH (GL), COMPUTER SCIENCE DEPARTMENT, ARIGNAR ANNA GOVERNMENT ARTS COLLEGE , CHEYYAR.
Page 8
• Message passing technique for communication between objects make the interface
descriptions with external system much simpler.
• Software complexity can be easily managed.

1.5 Object Oriented Languages


Object-oriented programming is not the right of any particular language. Like
structured programming , OOP concepts can be implemented using languages such as C and
Pascal.
The languages should support several of the OPP concepts to claim that they are object-
oriented. Depending upon the features they support, they can be classified into the following
two categories:

a) Object-based programming languages


b) Object-oriented programming languages

➢ Object-based programming languages:


Object-based programming languages is the style of programming that primarily
supports encapsulation and object identity. Major features that are required for object-based
programming are:

• Data encapsulation
• Data hiding and access mechanisms
• Automatic initialization and clear-up of objects
• Operator overloading
➢ Object-oriented programming languages:

Object-oriented programming incorporates all of object-based programming features


along with two additional features, namely, inheritance and dynamic binding. Object-
oriented programming can therefore be characterized by the following statement:

Object-based features + inheritance + dynamic binding

1.6 Beginning With C++

1.6.1 What is C++?


1.6.2 A Simple C++ Program
1.6.3 Structure of C++ Program

➢ What is C++?
• C++ is an object-oriented programming language.

A.PRAKASH (GL), COMPUTER SCIENCE DEPARTMENT, ARIGNAR ANNA GOVERNMENT ARTS COLLEGE , CHEYYAR.
Page 9
• Initially named ‘C with classes’, C++ was developed by Bjarne Stroustrup at
AT&Bell Laboratories in Murray Hill,New Jersey,USA,in the early eighties.
• Stroustrup, an admirer of simula67 and a strong supporter of C,wanted to
combine the best of both languages and create a more powerful language of
C.The result was C++.
• Therefore C++ is an extension of C with a major addition of the class
construct feature of Simula67.
• The class was a major addition to the original C language , Stroustrup called
the language ‘C with classes’. However, later in 1983,the name was changed
to C++.
• The idea of C++ comes from the C increment operator ++ ,thereby suggesting
that C++ is an augmented(incremented) version of C.
• C++ is a superset of C. Most of what we already know about C applies to C++
also.
• The three most important facilities that C++ adds on to C are classes , function
overloading ,and operator overloading.
• These features enable us to create abstract data types, inherit properties from
existing data types and support polymorphism, thus making C++ a truly object-
oriented language.
➢ A Simple C++ Program
Let us with a simple example of a C++ program that prints a string on the screen.

///////////////////////////[ PRINGING A STRING ]/////////////////////////////////////


#include <iostream.h> // include header file
main()
{
cout<<”c++ is better c.”; // c++ statement
}
// End of example
///////////////////////////////////////< program 2.1 >//////////////////////////////////////////

Program Features:
• Like C , the C++ program is a collection of functions.
• The example contains only one function,main().As usual ,execution begins at main().

A.PRAKASH (GL), COMPUTER SCIENCE DEPARTMENT, ARIGNAR ANNA GOVERNMENT ARTS COLLEGE , CHEYYAR.
Page 10
• The C++ program must have a main().
• C++ is a free-form language.
• The compiler ignores carriage returns and white spaces.Like C, the C++ statements
terminate with semicolons.
Comments
• C++ introduces a new comment symbol //(double slash).
• Comments start with a double slash symbol and terminate at the end of the line.
• A comment may start anywhere in the line and whatever follows till the end of the line
is ignored. Note that there is no closing symbol.
• The double slash comment is basically s single line comment. Multiline can be written
as follows:
//This is an example of
//C++ program to illustrate
//some of its features
The C comment symbols /*,*/ are still valid and are more suitable for multiline
comments. The following comment is allowed:
/* This is an example of
C++ program to illustrate
some of its features
*/
• We can use either or both styles in our programs.
• We can not insert a // stle comment within the text of a program line.
• For example ,the double slash comment cannot be used in the manner as shown below:
for (j = 0;j<n; /*loops n times */ j++)
Input Operator
The input operator, commonly known as the extraction operator (>>), is used with the
standard input stream, cin. As stated earlier, cin treats data as a stream of characters. These
characters flow from cin to the program through the input operator. The input operator works on
two operands, namely, the c in stream on its left and a variable on its right. Thus, the input
operator takes (extracts) the value through cin and stores it in the variable.
To understand the concept of an input operator, consider this example.
A program to demonstrate the working of an input operator.
#include

A.PRAKASH (GL), COMPUTER SCIENCE DEPARTMENT, ARIGNAR ANNA GOVERNMENT ARTS COLLEGE , CHEYYAR.
Page 11
using namespace, std;
int main () {
int a;
cin>>a;
a = a+1;
return 0;
}

In this example, the statement cin>> a takes an input from the user and stores it in the variable
a.
Output Operator
The output operator, commonly known as the insertion operator (<<), is used. The
standard output stream cout Like cin, cout also treats data as a stream of characters. These
characters flow from the program to cout through the output operator. The output operator
works on two operands, namely, the cout stream on its left and the expression to be displayed
on its right. The output operator directs (inserts) the value to cout.
To understand the concept of output operator, consider this example.

A program to demonstrate the working of an output operator.

#include iostream.h>
using namespace std;
int main () {
int a;
cin>>a;
a=a+1;
cout<<a;
return 0;
}
This example is similar to Example 1. The only difference is that the value of the variable a is
displayed through the instruction cout << a .
Cascading of Input/Output Operators
The cascading of the input and output operators refers to the consecutive occurrence of
input or output operators in a single statement.
To understand the concept of cascading of the input/output operator, consider these examples.
A program without cascading of the input/output operator.
#include iostream.h>
using namespace std;
int main () {
int a, b;
cin>>a;
A.PRAKASH (GL), COMPUTER SCIENCE DEPARTMENT, ARIGNAR ANNA GOVERNMENT ARTS COLLEGE , CHEYYAR.
Page 12
cin>>b;
cout<<"The value of a is";
cout<<a;
cout<<"The value of b is";
cout<<b;
return 0;
}
In this example, all cin and cout statements use separate input and output operators
respectively However, these statements can be combined by cascading the input and output
operators accordingly as shown in this example.
A program with cascading of the input/output operator
#include<iostream.h>
using namespace std;
int main () {
int a, b;
cin>>a>>b;
cout<<"The value of b is : "<<b;
cout<<"The value of a is "<<a;
return 0;
}
In this example, the cascaded input operators wait for the user to input two values and
the cascaded output operator first displays the message The value of a is: and then displays the
value stored in a. Similar is the case for the next statement.
It can be observed that cascading of the input/output operator improves the readability
and reduces the size of the program.
The iostream.h File
iostream: iostream stands for standard input-output stream. This header file
contains definitions of objects like cin, cout, cerr, etc. iomanip: iomanip stands for input-output
manipulators. The methods declared in these files are used for manipulating streams.
1.6.3 Structure of C++ Program
Programs are a sequence of instructions or statements. These statements form the
structure of a C++ program. C++ program structure is divided into various sections,
namely, headers, class definition, member functions definitions and main function.

A.PRAKASH (GL), COMPUTER SCIENCE DEPARTMENT, ARIGNAR ANNA GOVERNMENT ARTS COLLEGE , CHEYYAR.
Page 13
Note that C++ provides the flexibility of writing a program with or without a class and
its member functions definitions. A simple C++ program (without a class) includes comments,
headers, namespace, main() and input/output statements.

Comments are a vital element of a program that is used to increase the readability of a program
and to describe its functioning. Comments are not executable statements and hence, do not
increase the size of a file.

C++ supports two comment styles: single line comment and multiline comment. Single line
comments are used to define line-by-line descriptions. Double slash (//) is used to represent
single line comments. To understand the concept of single line comment, consider this
statement.
/ / An example to demonstrate single line comment It can also be written as
/ / An example to demonstrate
/ / single line comment
Multiline comments are used to define multiple lines descriptions and are represented as / * * /.
For example, consider this statement.
/* An example to demonstrate multiline comment */

A.PRAKASH (GL), COMPUTER SCIENCE DEPARTMENT, ARIGNAR ANNA GOVERNMENT ARTS COLLEGE , CHEYYAR.
Page 14
Generally, multiline comments are not used in C++ as they require more space on the line.
However, they are useful within the program statements where single line comments cannot be
used. For example, consider this statement.
for(int i = 0; i<10; //loop runs 10 times i++)
Compiler ignores everything written after the single line comment and hence, an error occurs.
Therefore, in this case multiline comments are used. For example, consider this statement.
for(int i = 0; i<10; /*loop runs 10 times */ i++)
Headers: Generally, a program includes various programming elements like built-in functions,
classes, keywords, constants, operators, etc., that are already defined in the standard C++
library. In order to use such pre-defined elements in a program, an appropriate header must be
included in the program. The standard headers contain the information like prototype, definition
and return type of library functions, data type of constants, etc. As a result, programmers do not
need to explicitly declare (or define) the predefined programming elements.
Standard headers are specified in a program through the preprocessor directive” #include. In
Figure, the iostream header is used. When the compiler processes the instruction
#inc1ude<iostream>, it includes the contents of iostream in the program. This enables the
programmer to use standard input, output and error facilities that are provided only through the
standard streams defined in <iostream>. These standard streams process data as a stream of
characters, that is, data is read and displayed in a continuous flow. The standard streams defined
in <iostream> are listed here.
• cin (pronounced “see in”) : It is the standard input stream that is associated with the standard
input device (keyboard) and is used to take the input from users.
• cout (pronounced “see out”) : It is the standard output stream that is associated with the
standard output device (monitor) and is used to display the output to users.
• cerr (pronounced “see err”) : It is the standard error stream that is associated with the
standard error device (monitor) and is used to report errors to the users. The cerr object does not
have a buffer (temporary storage area) and hence, immediately reports errors to users. ‘
• clog (pronounced “see log”): It is the buffered error stream that is associated with the standard
error device (computer screen) and is used to report errors to users. Unlike cerr, clog reports
errors to users only when the buffer is full
For many years, C++ applied C-style headers, that is, .h extension in the headers. However, the
standard C++ library introduced new-style headers that include only header name. Hence, the
most modem compilers do not require any extension, though they support the older .h
extension. Some of C-style headers and their equivalent C++ style headers are listed in Table.

A.PRAKASH (GL), COMPUTER SCIENCE DEPARTMENT, ARIGNAR ANNA GOVERNMENT ARTS COLLEGE , CHEYYAR.
Page 15
Namespace: Since its creation, C++ has gone through many changes by the C++ Standards
Committee. One of the new features added to this language is namespace. A namespace permits
grouping of various entities like classes, objects, functions and various C++ tokens, etc., under a
single name. Different users can create separate namespaces and thus can use similar names of
the entities. This avoids compile-time error that may exist due to identical-name conflicts.

The C++ Standards Committee has rearranged the entities of the standard library under a
namespace called std. In Figure, the statement using namespace std informs the compiler to
include all the entities present in the namespace std. The entities of a namespace can be
accessed in different ways which are listed here.
• By specifying the using directive
using namespace std;
cout<<“Hello World”;
• By specifying the full member name
std: :cout<<“Hello World”;
• By specifying the using declaration
using std:: cout;
cout<<“Hello World”;
As soon as the new-style header is included, its contents are included in the std namespace.
Thus, all the modern C++ compilers support these statements.
#include<iostream>

A.PRAKASH (GL), COMPUTER SCIENCE DEPARTMENT, ARIGNAR ANNA GOVERNMENT ARTS COLLEGE , CHEYYAR.
Page 16
using namespace std;
However, some old compilers may not support these statements. In that case, the statements are
replaced by this single statement.
#include<iostream.h>
Main Function: The main () is a startup function that starts the execution of a c++ program. All
C++ statements that need to be executed are written within main ( ). The compiler executes all
the instructions written within the opening and closing curly braces’ {}’ that enclose the body of
main ( ). Once all the instructions in main () are executed, the control passes out of main ( ),
terminating the entire program and returning a value to the operating system.
By default, main () in C++ returns an int value to the operating system. Therefore, main ()
should end with the return 0 statement. A return value zero indicates success and a non-zero
value indicates failure or error.
1.7 TOKENS
The smallest individual units in a program are known as tokens. C++ has the
following tokens:
1. Keywords
2. Identifiers
3. Constants
4. Strings
5. Special Symbols
6. Operators

➢ Keywords:
Keywords are pre-defined or reserved words in a programming language. Each
keyword is meant to perform a specific function in a program. Since keywords are referred
names for a compiler, they can’t be used as variable names because by doing so, we are
trying to assign a new meaning to the keyword which is not allowed. You cannot redefine
keywords. However, you can specify the text to be substituted for keywords before
compilation by using C/C++ preprocessor directives. C language supports 32 keywords
which are given below:

auto double int struct


break else long switch
case enum register typedef
char extern return union
const float short unsigned
continue for signed void
default goto sizeof volatile
do if static while

While in C++ there are 31 additional keywords other than C Keywords they are:

asm bool catch class


const_cast delete dynamic_cast explicit
export false friend inline
mutable namespace new operator

A.PRAKASH (GL), COMPUTER SCIENCE DEPARTMENT, ARIGNAR ANNA GOVERNMENT ARTS COLLEGE , CHEYYAR.
Page 17
private protected public reinterpret_cast
static_cast template this throw
true try typeid typename
using virtual wchar_t
➢ Identifiers:
Identifiers are used as the general terminology for the naming of variables, functions
and arrays. These are user-defined names consisting of an arbitrarily long sequence of letters
and digits with either a letter or the underscore(_) as a first character. Identifier names must
differ in spelling and case from any keywords. You cannot use keywords as identifiers; they
are reserved for special use. Once declared, you can use the identifier in later program
statements to refer to the associated value. A special kind of identifier, called a statement label,
can be used in goto statements.

There are certain rules that should be followed while naming c identifiers:

• They must begin with a letter or underscore(_).


• They must consist of only letters, digits, or underscore. No other special character is
allowed.
• It should not be a keyword.
• It must not contain white space.
• It should be up to 31 characters long as only the first 31 characters are significant.
• main: method name.
• a: variable name.

➢ Constants:
Constants are also like normal variables. But, the only difference is, their values
can not be modified by the program once they are defined. Constants refer to fixed values.
They are also called literals.
Constants may belong to any of the data type
Syntax:
const data_type variable_name; (or) const data_type *variable_name;

Types of Constants:
1. Integer constants – Example: 0, 1, 1218, 12482
2. Real or Floating-point constants – Example: 0.0, 1203.03, 30486.184
3. Octal & Hexadecimal constants – Example: octal: (013 )8 = (11)10, Hexadecimal:
(013)16 = (19)10
4. Character constants -Example: ‘a’, ‘A’, ‘z’
5. String constants -Example: “AnnaCollege”

➢ Strings:
Strings are nothing but an array of characters ended with a null character (‘\0’). This
null character indicates the end of the string. Strings are always enclosed in double-quotes.
Whereas, a character is enclosed in single quotes in C and C++.Declarations for String:

• char string[20] = {‘g’, ’e’, ‘e’, ‘k’, ‘s’, ‘f’, ‘o’, ‘r’, ‘g’, ’e’, ‘e’, ‘k’, ‘s’, ‘\0’};
• char string[20] = “geeksforgeeks”;

A.PRAKASH (GL), COMPUTER SCIENCE DEPARTMENT, ARIGNAR ANNA GOVERNMENT ARTS COLLEGE , CHEYYAR.
Page 18
• char string [] = “geeksforgeeks”;
• when we declare char as “string[20]”, 20 bytes of memory space is allocated for holding
the string value.
• When we declare char as “string[]”, memory space will be allocated as per the requirement
during the execution of the program.

➢ Special Symbols:
The following special symbols are used in C having some special meaning and
thus, cannot be used for some other purpose.[] () {}, ; * = #

• Brackets[]: Opening and closing brackets are used as array element reference. These
indicate single and multidimensional subscripts.
• Parentheses(): These special symbols are used to indicate function calls and function
parameters.
• Braces{}: These opening and ending curly braces mark the start and end of a block of code
containing more than one executable statement.
• Comma (, ): It is used to separate more than one statements like for separating parameters in
function calls.
• Colon(:): It is an operator that essentially invokes something called an initialization list.
• Semicolon(;): It is known as a statement terminator. It indicates the end of one logical
entity. That’s why each individual statement must be ended with a semicolon.
• Asterisk (*): It is used to create a pointer variable.
• Assignment operator(=): It is used to assign values.
• Pre-processor (#): The preprocessor is a macro processor that is used automatically by the
compiler to transform your program before actual compilation.

➢ Operators:
Operators are symbols that trigger an action when applied to C variables and other
objects. The data items on which operators act upon are called operands.

Depending on the number of operands that an operator can act upon, operators can be
classified as follows:

• Unary Operators: Those operators that require only a single operand to act upon are known
as unary operators.For Example increment and decrement operators
• Binary Operators: Those operators that require two operands to act upon are called binary
operators. Binary operators are classified into :
1. Arithmetic Operators
2. Relational Operators
3. Logical Operators
4. Assignment Operators
5. Conditional Operators
6. Bitwise Operators

A.PRAKASH (GL), COMPUTER SCIENCE DEPARTMENT, ARIGNAR ANNA GOVERNMENT ARTS COLLEGE , CHEYYAR.
Page 19
1.7 Basic Data Types

Basic data types in C++ is mainly divided into three types:

1. Primitive Data Types: These data types are built-in or predefined data types and can be
used directly by the user to declare variables. example: int, char , float, bool etc. Primitive
data types available in C++ are:
• Integer
• Character
• Boolean
• Floating Point
• Double Floating Point
• Valueless or Void
• Wide Character
2. Derived Data Types: The data-types that are derived from the primitive or built-in
datatypes are referred to as Derived Data Types. These can be of four types namely:
• Function
• Array
• Pointer
• Reference
3. Abstract or User-Defined Data Types: These data types are defined by user itself. Like,
defining a class in C++ or a structure. C++ provides the following user-defined datatypes:
• Class
• Structure
• Union
• Enumeration
• Typedef defined DataType

➢ Primitive Data Types:

• nteger:
Keyword used for integer data types is int. Integers typically requires 4 bytes of
memory space and ranges from -2147483648 to 2147483647.

• Character:
Character data type is used for storing characters. Keyword used for character data
type is char. Characters typically requires 1 byte of memory space and ranges from -128 to 127
or 0 to 255.

• Boolean:
Boolean data type is used for storing boolean or logical values. A boolean variable
can store either true or false. Keyword used for boolean data type is bool.

• Floating Point:

A.PRAKASH (GL), COMPUTER SCIENCE DEPARTMENT, ARIGNAR ANNA GOVERNMENT ARTS COLLEGE , CHEYYAR.
Page 20
Floating Point data type is used for storing single precision floating point values or
decimal values. Keyword used for floating point data type is float. Float variables typically
requires 4 byte of memory space.

• Double Floating Point:


Double Floating Point data type is used for storing double precision floating
point values or decimal values. Keyword used for double floating point data type is double.
Double variables typically requires 8 byte of memory space.

• void:
Void means without any value. void datatype represents a valueless entity. Void data
type is used for those function which does not returns a value.

• Wide Character:
Wide character data type is also a character data type but this data type has size
greater than the normal 8-bit datatype. Represented by wchar_t. It is generally 2 or 4 bytes
long.

➢ Data type modifiers available in C++ are:

• Signed
• Unsigned
• Short
• Long

1.8 Scope Resolution Operator


The scope resolution operator ( :: ) is used for several reasons. For
example: If the global variable name is same as local variable name, the scope resolution
operator will be used to call the global variable. It is also used to define a function outside
the class and used to access the static variables of class.
Here an example of scope resolution operator in C++ language,
Example
#include <iostream>
using namespace std;
char a = 'm';
static int b = 50;

int main() {
char a = 's';

cout << "The static variable : "<< ::b;

A.PRAKASH (GL), COMPUTER SCIENCE DEPARTMENT, ARIGNAR ANNA GOVERNMENT ARTS COLLEGE , CHEYYAR.
Page 21
cout << "\nThe local variable : " << a;
cout << "\nThe global variable : " << ::a;

return 0;
}
Output
The static variable : 50
The local variable : s
The global variable : m

1.9 Manipulators
Manipulators are helping functions that can modify the input/output stream. It
does not mean that we change the value of a variable, it only modifies the I/O stream using
insertion (<<) and extraction (>>) operators.
For example, if we want to print the hexadecimal value of 100 then we can print it as:
cout<<setbase(16)<<100
Types of Manipulators
There are various types of manipulators:
1.9.1 Manipulators without arguments: The most important manipulators defined by
the IOStream library are provided below.

• endl: It is defined in ostream. It is used to enter a new line and after entering a new line it
flushes (i.e. it forces all the output written on the screen or in the file) the output stream.
• ws: It is defined in istream and is used to ignore the whitespaces in the string sequence.
• ends: It is also defined in ostream and it inserts a null character into the output stream. It
typically works with std::ostrstream, when the associated output buffer needs to be null-
terminated to be processed as a C string.
• flush: It is also defined in ostream and it flushes the output stream, i.e. it forces all the
output written on the screen or in the file. Without flush, the output would be the same,
but may not appear in real-time.
Examples:

#include <iostream>
#include <istream>
#include <sstream>
#include <string>

using namespace std;

int main()
{
istringstream str(" Programmer");

A.PRAKASH (GL), COMPUTER SCIENCE DEPARTMENT, ARIGNAR ANNA GOVERNMENT ARTS COLLEGE , CHEYYAR.
Page 22
string line;
// Ignore all the whitespace in string
// str before the first word.
getline(str >> std::ws, line);

// you can also write str>>ws


// After printing the output it will automatically
// write a new line in the output stream.
cout << line << endl;

// without flush, the output will be the same.


cout << "only a test" << flush;

// Use of ends Manipulator


cout << "\na";

// NULL character will be added in the Output


cout << "b" << ends;
cout << "c" << endl;

return 0;
}

Output:

Programmer
only a test
abc
1.9.2 Manipulators with Arguments:
Some of the manipulators are used with the argument like setw (20), setfill (‘*’),
and many more. These all are defined in the header file. If we want to use these manipulators
then we must include this header file in our program.
For Example, you can use following manipulators to set minimum width and fill the empty
space with any character you want: std::cout << std::setw (6) << std::setfill (’*’);
• Some important manipulators in <iomanip> are:

1. setw (val): It is used to set the field width in output operations.


2. setfill (c): It is used to fill the character ‘c’ on output stream.
3. setprecision (val): It sets val as the new value for the precision of floating-point values.
4. setbase(val): It is used to set the numeric base value for numeric values.
5. setiosflags(flag): It is used to set the format flags specified by parameter mask.
6. resetiosflags(m): It is used to reset the format flags specified by parameter mask.

• Some important manipulators in <ios> are:

1. showpos: It forces to show a positive sign on positive numbers.


2. noshowpos: It forces not to write a positive sign on positive numbers.

A.PRAKASH (GL), COMPUTER SCIENCE DEPARTMENT, ARIGNAR ANNA GOVERNMENT ARTS COLLEGE , CHEYYAR.
Page 23
3. showbase: It indicates the numeric base of numeric values.
4. uppercase: It forces uppercase letters for numeric values.
5. nouppercase: It forces lowercase letters for numeric values.
6. fixed: It uses decimal notation for floating-point values.
7. scientific: It uses scientific floating-point notation.
8. hex: Read and write hexadecimal values for integers and it works same as the setbase(16).
9. dec: Read and write decimal values for integers i.e. setbase(10).
10. oct: Read and write octal values for integers i.e. setbase(10).
11. left: It adjusts output to the left.
12. right: It adjusts output to the right.

Example:
#include <iomanip>
#include <iostream>
using namespace std;

int main()
{
double A = 100;
double B = 2001.5251;
double C = 201455.2646;

// We can use setbase(16) here instead of hex

// formatting
cout << hex << left << showbase << nouppercase;

// actual printed part


cout << (long long)A << endl;

// We can use dec here instead of setbase(10)

// formatting
cout << setbase(10) << right << setw(15)
<< setfill('_') << showpos
<< fixed << setprecision(2);

// actual printed part


cout << B << endl;

// formatting
cout << scientific << uppercase
<< noshowpos << setprecision(9);

// actual printed part


cout << C << endl;
}

Output:

A.PRAKASH (GL), COMPUTER SCIENCE DEPARTMENT, ARIGNAR ANNA GOVERNMENT ARTS COLLEGE , CHEYYAR.
Page 24
0x64
_______+2001.53
2.014552646E+05

1.10 Expressions
An expression is a combination of operators, constants and variables. An
expression may consist of one or more operands, and zero or more operators to produce
a value.

Example:
a+b
c
s-1/7*f
.
.
etc
Types of Expressions:
Expressions may be of the following types :
A.PRAKASH (GL), COMPUTER SCIENCE DEPARTMENT, ARIGNAR ANNA GOVERNMENT ARTS COLLEGE , CHEYYAR.
Page 25
• Constant expressions:
Constant Expressions consists of only constant values. A constant value is one that
doesn’t change.
Examples:
5, 10 + 5 / 6.0, 'x’
• Integral expressions:
Integral Expressions are those which produce integer results after implementing
all the automatic and explicit type conversions.
Examples:
x, x * y, x + int( 5.0)
where x and y are integer variables.

• Floating expressions:
Float Expressions are which produce floating point results after implementing all
the automatic and explicit type conversions.
Examples:
x + y, 10.75
where x and y are floating point variables.
• Relational expressions:
Relational Expressions yield results of type bool which takes a value true or false.
When arithmetic expressions are used on either side of a relational operator, they will be
evaluated first and then the results compared. Relational expressions are also known as

A.PRAKASH (GL), COMPUTER SCIENCE DEPARTMENT, ARIGNAR ANNA GOVERNMENT ARTS COLLEGE , CHEYYAR.
Page 26
Boolean expressions.
Examples:
x <= y, x + y > 2
• Logical expressions:
Logical Expressions combine two or more relational expressions and produces
bool type results.
Examples:
x > y && x == 10, x == 10 || y == 5
• Pointer expressions:
Pointer Expressions produce address values.
Examples:
&x, ptr, ptr++
where x is a variable and ptr is a pointer.
• Bitwise expressions:
Bitwise Expressions are used to manipulate data at bit level. They are basically
used for testing or shifting bits.
Examples:
x << 3
shifts three bit position to left

y >> 1
shifts one bit position to right.
Shift operators are often used for multiplication and division by powers of two.
1.11Control Structures
Control structures form the basic entities of a “structured programming
language“. We all know languages like C/C++ or Java are all structured programming
languages. Control structures are used to alter the flow of execution of the program. Why do
we need to alter the program flow ? The reason is “decision making“! In life, we may be given
with a set of option like doing “Electronics” or “Computer science”. We do make a decision by
analyzing certain conditions (like our personal interest, scope of job opportunities etc). With the
decision we make, we alter the flow of our life’s direction. This is exactly what happens in a
C/C++ program. We use control structures to make decisions and alter the direction of program
flow in one or the other path(s) available.
There are three types of control structures available in C and C++

1) Sequence structure (straight line paths)


2) Selection structure (one or many branches)
3)Loop structure (repetition of a set of activities)

All the 3 control structures and its flow of execution is represented in the flow charts given
below.

A.PRAKASH (GL), COMPUTER SCIENCE DEPARTMENT, ARIGNAR ANNA GOVERNMENT ARTS COLLEGE , CHEYYAR.
Page 27
Control statements in C/C++ to implement control structures

We have to keep in mind one important fact:- all program processes can be
implemented with these 3 control structures only. That’s why I wrote “control structures are the
basic entities of a structured programming language“. To implements these “control
structures” in a C/C++ program, the language provides ‘control statements’. So to implement a
particular control structure in a programming language, we need to learn how to use the relevant
control statements in that particular language.
The control statements are:-

• Switch
• If
• If Else
• While
• Do While
• For
As shown in the flow charts:-

A.PRAKASH (GL), COMPUTER SCIENCE DEPARTMENT, ARIGNAR ANNA GOVERNMENT ARTS COLLEGE , CHEYYAR.
Page 28
• Selection structures are implemented using If , If Else and Switch statements.
• Looping structures are implemented using While, Do While and For statements.

Selection structures

Selection structures are used to perform ‘decision making‘ and then branch the
program flow based on the outcome of decision making. Selection structures are implemented in
C/C++ with If, If Else and Switch statements. If and If Else statements are 2 way branching
statements where as Switch is a multi branching statement.

The simple If statement

The syntax format of a simple if statement is as shown below.

A.PRAKASH (GL), COMPUTER SCIENCE DEPARTMENT, ARIGNAR ANNA GOVERNMENT ARTS COLLEGE , CHEYYAR.
Page 29
if (expression) // This expression is evaluated. If expression is TRUE statements inside the
braces will be executed
{
statement 1;
statement 2;
}
statement 1;// Program control is transfered directly to this line, if the expression is FALSE
statement 2;
The expression given inside the brackets after if is evaluated first. If the expression is true, then
statements inside the curly braces that follow if(expression) will be executed. If the expression is
false, the statements inside curly braces will not be executed and program control goes directly to
statements after curly braces.

Example program to demo “If” statement

Problem:-
A simple example program to demo the use of If, If Else and Switch is shown here. An integer
value is collected from user.
If the integer entered by user is 1 – output on screen “UNITED STATES”. If the integer is 2 –
output “SPAIN”, If the integer is 3 output “INDIA”. If the user enters some other value – output
“WRONG ENTRY”.

Note:- The same problem is used to develop example programs for “if else” and “switch”
statements
#include
void main()
{
int num;
printf("Hello user, Enter a number");
scanf("%d",&num); // Collects the number from user
if(num==1)
{
printf("UNITED STATES");
}
if(num==2)
{
printf("SPAIN");
}
if(num==3)
{
printf("INDIA");
}
}

A.PRAKASH (GL), COMPUTER SCIENCE DEPARTMENT, ARIGNAR ANNA GOVERNMENT ARTS COLLEGE , CHEYYAR.
Page 30
The If Else statement.

Syntax format for If Else statement is shown below.

if(expression 1)// Expression 1 is evaluated. If TRUE, statements inside the curly braces are
executed.
{ //If FALSE program control is transferred to immedate else if statement.
statement 1;
statement 2;
}
else if(expression 2)// If expression 1 is FALSE, expression 2 is evaluated.
{
statement 1;
statement 2;
}
else if(expression 3) // If expression 2 is FALSE, expression 3 is evaluated
{
statement 1;
statement 2;
}
else // If all expressions (1, 2 and 3) are FALSE, the statements that follow this else (inside curly
braces) is executed.
{
statement 1;
statement 2;
}
other statements;
The execution begins by evaluation expression 1. If it is TRUE, then statements
inside the immediate curly braces is evaluated. If it is FALSE, program control is transferred
directly to immediate else if statement. Here expression 2 is evaluated for TRUE or FALSE. The
process continues. If all expressions inside the different if and else if statements are FALSE, then
the last else statement (without any expression) is executed along with the statements 1 and 2
inside the curly braces of last else statement.

Example program to demo “If Else”

#include
void main()
{
int num;
printf("Hello user, Enter a number");
scanf("%d",&num); // Collects the number from user
if(num==1)
{

A.PRAKASH (GL), COMPUTER SCIENCE DEPARTMENT, ARIGNAR ANNA GOVERNMENT ARTS COLLEGE , CHEYYAR.
Page 31
printf("UNITED STATES");
}
else if(num==2)
{
printf("SPAIN");
}
else if(num==3)
{
printf("INDIA");
}
else
{
printf("WRONG ENTRY"); // See how else is used to output "WRONG ENTRY"
}
}
Note:- Notice how the use of If Else statements made program writing easier. Compare this with
above program using simple If statement only.

Switch statement

Switch is a multi branching control statement. Syntax for switch statement is shown below.

switch(expression)// Expression is evaluated. The outcome of the expression should be an integer


or a character constant
{
case value1: // case is the keyword used to match the integer/character constant from expression.
//value1, value2 ... are different possible values that can come in expression
statement 1;
statement 2;
break; // break is a keyword used to break the program control from switch block.
case value2:
statement 1;
statement 2;
break;
default: // default is a keyword used to execute a set of statements inside switch, if no case values
match the expression value.
statement 1;
statement 2;
break;
}
Execution of switch statement begins by evaluating the expression inside the switch
keyword brackets. The expression should be an integer (1, 2, 100, 57 etc ) or a character constant
like ‘a’, ‘b’ etc. This expression’s value is then matched with each case values. There can be any
number of case values inside a switch statements block. If first case value is not matched with
the expression value, program control moves to next case value and so on. When a case value

A.PRAKASH (GL), COMPUTER SCIENCE DEPARTMENT, ARIGNAR ANNA GOVERNMENT ARTS COLLEGE , CHEYYAR.
Page 32
matches with expression value, the statements that belong to a particular case value are
executed.

Notice that last set of lines that begins with default. The word default is a keyword in C/C++.
When used inside switch block, it is intended to execute a set of statements, if no case values
matches with expression value. So if no case values are matched with expression value, the set of
statements that follow default: will get executed.

Note: Notice the break statement used at the end of each case values set of statements. The word
break is a keyword in C/C++ used to break from a block of curly braces. The switch block has
two curly braces { }. The keyword break causes program control to exit from switch block.

Example program to demo working of “switch”

#include
void main()
{
int num;
printf("Hello user, Enter a number");
scanf("%d",&num); // Collects the number from user
switch(num)
{
case 1:
printf("UNITED STATES");
break;
case 2:
printf("SPAIN");
break;
case 3:
printf("INDIA");
default:
printf("WRONG ENTRY");
}
}
Note:- Switch statement is used for multiple branching. The same can be implemented
using nested “If Else” statements. But use of nested if else statements make program writing
tedious and complex. Switch makes it much easier. Compare this program with above one.

➢ Loop structures

A.PRAKASH (GL), COMPUTER SCIENCE DEPARTMENT, ARIGNAR ANNA GOVERNMENT ARTS COLLEGE , CHEYYAR.
Page 33
A loop structure is used to execute a certain set of actions for a predefined
number of times or until a particular condition is satisfied. There are 3 control statements
available in C/C++ to implement loop structures. While, Do while and For statements.

The while statement

Syntax for while loop is shown below:


while(condition)// This condition is tested for TRUE or FALSE. Statements inside curly braces
are executed as long as condition is TRUE
{
A.PRAKASH (GL), COMPUTER SCIENCE DEPARTMENT, ARIGNAR ANNA GOVERNMENT ARTS COLLEGE , CHEYYAR.
Page 34
statement 1;
statement 2;
statement 3;
}
The condition is checked for TRUE first. If it is TRUE then all statements inside curly braces are
executed.Then program control comes back to check the condition has changed or to check if it
is still TRUE. The statements inside braces are executed repeatedly, as long as the condition is
TRUE. When the condition turns FALSE, program control exits from while loop.

Note:- while is an entry controlled loop. Statement inside braces are allowed to execute only if
condition inside while is TRUE.

Example program to demo working of “while loop”

An example program to collect a number from user and then print all numbers from zero to that
particular collected number is shown below. That is, if user enters 10 as input, then numbers
from 0 to 10 will be printed on screen.

Note:- The same problem is used to develop programs for do while and for loops

#include
void main()
{
int num;
int count=0; // count is initialized as zero to start printing from zero.
printf("Hello user, Enter a number");
scanf("%d",&num); // Collects the number from user
while(count<=num) // Checks the condition - if value of count has reached value of num or not. {
printf("%d",count); count=count+1; // value of count is incremented by 1 to print next number. }
}

The do while statement

Syntax for do while loop is shown below:


do
{
statement 1;
statement 2;
statement 3;
}
while(condition);
Unlike while, do while is an exit controlled loop. Here the set of statements inside braces are
executed first. The condition inside while is checked only after finishing the first time execution
of statements inside braces. If the condition is TRUE, then statements are executed again. This

A.PRAKASH (GL), COMPUTER SCIENCE DEPARTMENT, ARIGNAR ANNA GOVERNMENT ARTS COLLEGE , CHEYYAR.
Page 35
process continues as long as condition is TRUE. Program control exits the loop once the
condition turns FALSE.

Example program to demo working of "do while"

#include
void main()
{
int num;
int count=0; // count is initialized as zero to start printing from zero.
printf("Hello user, Enter a number");
scanf("%d",&num); // Collects the number from user
do
{
printf("%d",count); // Here value of count is printed for one time intially and then only condition
is checked.
count=count+1; // value of count is incremented by 1 to print next number.
}while(count<=num); }

The for statement

Syntax of for statement is shown below:

for(initialization statements;test condition;iteration statements)


{
statement 1;
statement 2;
statement 3;
}
The for statement is an entry controlled loop. The difference between while and for is in the
number of repetitions. The for loop is used when an action is to be executed for a predefined
number of times. The while loop is used when the number of repetitions is not predefined.

Working of for loop:


The program control enters the for loop. At first it execute the statements given as initialization
statements. Then the condition statement is evaluated. If conditions are TRUE, then the block of
statements inside curly braces is executed. After executing curly brace statements fully, the
control moves to the "iteration" statements. After executing iteration statements, control comes
back to condition statements. Condition statements are evaluated again for TRUE or FALSE. If
TRUE the curly brace statements are executed. This process continues until the condition turns
FALSE.

Note 1:- The statements given as "initialization statements" are executed only once, at the
beginning of a for loop.
Note 2: There are 3 statements given to a for loop as shown. One for initialization purpose, other
A.PRAKASH (GL), COMPUTER SCIENCE DEPARTMENT, ARIGNAR ANNA GOVERNMENT ARTS COLLEGE , CHEYYAR.
Page 36
for condition testing and last one for iterating the loop. Each of these 3 statements are separated
by semicolons.

Example program to demo working of "for loop"

#include
void main()
{
int num,count;
printf("Hello user, Enter a number");
scanf("%d",&num); // Collects the number from user
for(count=0;count<=num;count++)// count is initialized to zero inside for statement. The
condition is checked and statements are executed. { printf("%d",count); // Values from 0 are
printed. } }
So that is all about "control statements" in C/C++ language. If you have any doubts ask in
comments section.

A.PRAKASH (GL), COMPUTER SCIENCE DEPARTMENT, ARIGNAR ANNA GOVERNMENT ARTS COLLEGE , CHEYYAR.
Page 37

You might also like