SlideShare a Scribd company logo
Table of Contents Unit /Chapters
Unit-I: Object Oriented Programming in C++
Chapter 1: Revision Tour of Class XI
Chapter 2: Classes and Object
Chapter 3: Constructor and Destructor
Chapter 4: Inheritance
Chapter 5: Data File Handling
Unit-II : Data Structure
Chapter 6: Arrays, Stacks, Queues And Linked List
Unit-III : Database Management Systems and SQL
Chapter 7: DBMS & Structured Query Language
Unit-IV : Boolean Algebra
Chapter 8: Boolean Algebra
Unit- V : Networking and Communication Technology
Chapter 9: Networking and Communication Technology
COURSE DESIGN
Unit Topic Marks
I Object Oriented Programming in C++ 30
II Data Structure 14
III Database Management Systems and SQL 8
IV Boolean Algebra 8
V Networking and Communication Technology 10
TOTAL 70
BASIC CONCEPTS OF C++ CLASS 12
BASIC CONCEPTS OF C++ CLASS 12
• Unit-I
• Objective Oriented Programming in C++
• Revision Tour of Class XI Chapter: 01
• Keywords: Keywords are the certain reserved words that convey a special
meaning to the compiler. These are reserve for special purpose and must
not be used as identifier name.eg for , if, else , this , do, etc.
• Identifiers: Identifiers are programmer defined names given to the
various program elements such as variables, functions, arrays, objects,
classes, etc.. It may contain digits, letters and underscore, and must begin
with a letter or underscore. C++ is case sensitive as it treats upper and
lower case letters differently. A keyword can not be used as an identifiers.
The following are some valid identifiers:
• Pen time580 s2e2r3 _dos _HJI3_JK
• Data Types in C++: Data types are means to identify the types of
data and associated operations of handling it. Data types in C++ are of
two types:
• 1. Fundamental or Built-in data types: These data types are already
known to compiler. These are the data types those are not composed
of other data types. There are following fundamental data types in
C++:
• (i) int data type (for integer) (ii) char data type (for characters)
• (iii) float data type (for floating point numbers) (iv) double data type
• Data Type Modifiers: There are following four data type modifiers
in C++ , which may be used to modify the fundamental data types to
fit various situations more precisely:
• (i) signed (ii) unsigned (iii) long (iv) short
• Variables: A named memory location, whose contains can be changed with in program
execution is known as variable. OR
• A variable is an identifier that denotes a storage location, which contains can be varied
during program execution.
• Declaration of Variables: Syntax for variable declaration is:
• datatypes variable_name1, variable_name2, variable_name3,……………. ;
• We can also initialize a variable at the time of declaration by using following syntax:
• datatypes variable_name = value;
• In C++ both the declaration and initialization of a variable can be done simultaniouly at
the place where the variable is used first time this feature is known as dynamic
initialization. e.g.,
• float avg;
• avg = sum/count;
• then above two statements can be combined in to one as follows:
• float avg = sum/count;
• Constant: A named memory location, whose contains cannot be
changed with in program execution is known as constant. OR
• A constant is an identifier that denotes a storage location, which
contains cannot be varied during program execution.
• Syntax for constant declaration is:
• const datatypes constant_name = value ;
• e.g., const float pi = 3,14f ;
• Conditional operator ( ? : ): The conditional operator (? :) is a
ternary operator i.e., it require three operands. The general form of
conditional operator is:
• expression1? expression2: expression3 ; Where expression1 is a
logical expression , which is either true or false.
• If expression1 evaluates to true i.e., 1, then the value of whole
expression is the value of expression2, otherwise, the value of the
whole expression is the value of expression3. For example
• min = a<b? a : b ;
• Type Conversion: The process of converting one predefined data type into another is called
type conversion.
• C++ facilitates the type conversion in two forms:
• (i) Implicit type conversion:- An implicit type conversion is a conversion performed by the
compiler without programmer’s intervention. An implicit conversion is applied generally
whenever different data types are intermixed in an expression. The C++ compiler converts all
operands upto the data type of the largest data type’s operand, which is called type promotion.
• (ii) Explicit type conversion :- An explicit type conversion is user-defined that forces an expression
to be of specific data type.
• Type Casting:- The explicit conversion of an operand to a specific type is called type casting.
• Type Casting Operator - (type) :-Type casting operators allow you to convert a data item of a
given type to another data type. To do so , the expression or identifier must be preceded by the
name of the desired data type , enclosed in parentheses . i. e.,
• (data type) expression
• Where data type is a valid C++ data type to which the conversion is to be done. For example , to
make sure that the expression (x+y/2) evaluates to type float , write it as:
• (float) (x+y/2)
 Some important Syntax in C++:
1. if Statement
if ( < conditional expression > ) { < statement-1
or block-1>;
// statements to be executed when conditional
expression is true. }
[ else { < statement-2 or block-2>;
// statements to be executed when conditional
expression is false. } ]
BASIC CONCEPTS OF C++ CLASS 12
3. switch Statement :- switch (expression/variable)
{ case value_1: statement -1;
break;
case value_2: statement -2;
break;
:
:
case value_n: statement -n;
break;
[ default: statement -m ]
}
4. The for Loop:
for(initialization_expression(s);
loop_Condition; update_expression)
{
Body of loop
}
5. while Loop:
while (loop_condition)
{
Loop_body
}
6. do-while loop:
do
{ Loop_body
}while (loop_condition);
The Working of Break Statement
BASIC CONCEPTS OF C++ CLASS 12
2. User-defined function :- The functions which are defined by user for a specific purpose is known as
user-defined function. For using a user-defined function it is required, first define it and then using.
Declaration of user-defined Function:
Return_type function_name(List of formal parameters)
{
Body of the function
}
Calling a Function:- When a function is called then a list of actual parameters is supplied that should
match with formal parameter list in number, type and order of arguments.
Syntax for calling a function is:
function_name ( list of actual parameters );
e.g.,
#include <iostream>
int addition (int a, int b)
{ int r;
r=a+b;
return (r); }
void main ( )
{ int z ;
z = addition (5,3);
cout<< "The result is " << z;
}
The result is 8
Call by Value (Passing by value) :- The call by value method of passing arguments to a
function copies the value of actual parameters into the formal parameters , that is, the
function creates its own copy of argument values and then use them, hence any chance made
in the parameters in function will not reflect on actual parameters . The above given program
is an example of call by value.
Call by Reference ( Passing by Reference) :- The call by reference method uses a different
mechanism. In place of passing value to the function being called , a reference to the original
variable is passed . This means that in call by reference method, the called function does not
create its own copy of original values , rather, its refers to the original values only by
different names i.e., reference . thus the called function works the original data and any
changes are reflected to the original values.
BASIC CONCEPTS OF C++ CLASS 12
 Scope of Identifier :- The part of program in which an identifier can be accessed is
known as scope of that identifier. There are four kinds of scopes in C++
(i) Local Scope :- An identifier declare in a block ( { } ) is local to that block and can be used
only in it.
(ii) Function Scope :- The identifier declare in the outermost block of a function have function
scope.
(iii) File Scope ( Global Scope) :- An identifier has file scope or global scope if it is declared
outside all blocks i.e., it can be used in all blocks and functions.
(iv) Class Scope :- A name of the class member has class scope and is local to its class.
BASIC CONCEPTS OF C++ CLASS 12
 Defining Structure :-
struct< Name of Structure >
{
<datatype>< data-member 1>;
<datatype>< data-member 2>;
<datatype>< data-member 3>;
…
…
<datatype>< data-member n>;
} ;
Declaring Structure Variable :-
struct< Name of Structure >
{
<datatype>< data-member 1>;
<datatype>< data-member 2>;
<datatype>< data-member 3>;
…
…
<datatype>< data-member n>;
} var1, var2,….., varn ;
We can declare the structure type variables separately (after defining of structure) using following syntax:
Structure_name var1, var2, …… ….., var_n;
Accessing Structure Elements :- To access structure element , dot operator is used. It is denoted by (.). The general form of accessing structure
element is :
Structure_Variable_Name.element_name
 Pointer:- Pointer is a variable that holds a memory address of another variable of same type.
Declaration and Initialization of Pointers :
Syntax :
Datatype *variable_name;
e.g., int *p; float *p1; char *c;
Two special unary operator * and & are used with pointers. The & is a unary operator that returns the memory address of its
operand.
e.g., int a = 10; int *p; p = &a;
Pointer arithmetic: Two arithmetic operations, addition and subtraction, may be performed on pointers. When you add 1 to a
pointer, you are actually adding the size of whatever the pointer is pointing at. That is, each time a pointer is incremented by 1, it
points to the memory location of the next element of its base type.
e.g. int *p; p++;
If current address of p is 1000, then p++ statement will increase p to 1002, not 1001.
Adding 1 to a pointer actually adds the size of pointer’s base type.
Base address : A pointer holds the address of the very first memory location of array where it is pointing to. The address of the
first memory location of array is known as BASE ADDRESS.
Dynamic Allocation Operators : C++ dynamic allocation operators allocate memory from the free store/heap/pool, the pool of
unallocated heap memory provided to the program. C++ defines two operators new and delete that perform the task of allocating
and freeing memory during runtime.
Pointers and Arrays : C++ treats the name of an array as constant pointer which contains base address i.e address of first memory
location of array.
 typedef :- The typedef keyword allows to create alias for data types. the syntax is:
typedef existing_data_type new_name ;
e.g. typedef int num;
 #define Preprocessor Directive: The # define directive creates symbolic constant, constants that are represent as
macros.
Macros: Macros are preprocessor directive created using # define that serve as symbolic
constants. They are created to simplify and reduce the amount of repetitive coding
e.g.1
#define PI 3.14
Here PI is defined as a macro. It will replace 3.14 in place of PI throughout the program.
e.g. 2
#define max (a, b) a>b? a: b
Defines the macro max, taking two arguments a and b. This macro may be called like any
function. Therefore, after preprocessing
A = max(x, y);
Becomes A = x>y?x :y ;
 Function Overloading: Function overloading is the process of defining and using functions with same name having
different argument list and/or different return types. These functions are differentiated during the calling process by the number,
order and types of arguments passed to these functions.
Example:
int Add (int ,int) ;
double Add (double ,double) ;
float Add (int ,float) ;
Short Answer Type Questions (2-Marks)
1. Define Macro with suitable example.
2. Explain in brief the purpose of function prototype with the help of a suitable example.
3. What is the difference between Global Variable and Local Variable?
4. What is the difference between Object Oriented Programming and Procedural Programming?
5. What is the difference between Global Variable and Local Variable? Also, give a suitable C++
code to illustrate both.
6. Differentiate between ordinary function and member functions in C++. Explain with an
example.
7. What is the difference between call by reference and call by value with respect to memory
allocation? Give a suitable example to illustrate using C++ code.
8. What is the difference between actual and formal parameter ? Give a suitable example to
illustrate using a C++ code.
9. Differentiate between a Logical Error and Syntax Error. Also give suitable examples of each in
C++.
10. Find the correct identifiers out of the following, which can be used for naming variable,
constants or functions in a C++ program :
While, for, Float, new, 2ndName, A%B, Amount2, _Counter
11. Out of the following, find those identifiers, which cannot be used for naming Variable,
Constants or Functions in a C++ program :
_Cost, Price*Qty, float, Switch, Address One, Delete, Number12, do
12. Find the correct identifiers out of the following, which can be used for naming Variable,
Constants or Functions in a C++ program :
For, while, INT, NeW, delete, 1stName, Add+Subtract, name1
BASIC CONCEPTS OF C++ CLASS 12
BASIC CONCEPTS OF C++ CLASS 12
BASIC CONCEPTS OF C++ CLASS 12

More Related Content

What's hot (20)

PPTX
C++
k v
 
PDF
Introduction to C++
Pranali Chaudhari
 
PDF
Fnctions part2
yndaravind
 
PDF
Structure In C
yndaravind
 
PDF
Data file handling
Prof. Dr. K. Adisesha
 
PDF
C++ version 1
JIGAR MAKHIJA
 
PDF
C++ Version 2
JIGAR MAKHIJA
 
DOC
C fundamental
Selvam Edwin
 
PDF
Intake 38 2
Mahmoud Ouf
 
PPT
Methods in C#
Prasanna Kumar SM
 
PPTX
C++ Basics
Himanshu Sharma
 
PPTX
Chapter 2.datatypes and operators
Jasleen Kaur (Chandigarh University)
 
PDF
Class and object
Prof. Dr. K. Adisesha
 
PPT
Object-Oriented Programming Using C++
Salahaddin University-Erbil
 
PPT
01 c++ Intro.ppt
Tareq Hasan
 
PPTX
OODP Unit 1 OOPs classes and objects
Shanmuganathan C
 
PDF
User defined functions in matlab
Infinity Tech Solutions
 
PDF
C++ interview question
Durgesh Tripathi
 
PPT
Getting started with c++
K Durga Prasad
 
PDF
Function pointer - Wikipedia, the free encyclopedia
Rishikesh Agrawani
 
C++
k v
 
Introduction to C++
Pranali Chaudhari
 
Fnctions part2
yndaravind
 
Structure In C
yndaravind
 
Data file handling
Prof. Dr. K. Adisesha
 
C++ version 1
JIGAR MAKHIJA
 
C++ Version 2
JIGAR MAKHIJA
 
C fundamental
Selvam Edwin
 
Intake 38 2
Mahmoud Ouf
 
Methods in C#
Prasanna Kumar SM
 
C++ Basics
Himanshu Sharma
 
Chapter 2.datatypes and operators
Jasleen Kaur (Chandigarh University)
 
Class and object
Prof. Dr. K. Adisesha
 
Object-Oriented Programming Using C++
Salahaddin University-Erbil
 
01 c++ Intro.ppt
Tareq Hasan
 
OODP Unit 1 OOPs classes and objects
Shanmuganathan C
 
User defined functions in matlab
Infinity Tech Solutions
 
C++ interview question
Durgesh Tripathi
 
Getting started with c++
K Durga Prasad
 
Function pointer - Wikipedia, the free encyclopedia
Rishikesh Agrawani
 

Similar to BASIC CONCEPTS OF C++ CLASS 12 (20)

PDF
Computer science_xii_2016
Ritika sahu
 
PPT
Data Handling
Praveen M Jigajinni
 
PPT
C cpluplus 2
sanya6900
 
PPTX
OOPS (object oriented programming) unit 1
AnamikaDhoundiyal
 
PPTX
Concept of c data types
Manisha Keim
 
PPT
Basic concept of c++
shashikant pabari
 
PPTX
C++ theory
Shyam Khant
 
PPTX
OOC MODULE1.pptx
1HK19CS090MOHAMMEDSA
 
PDF
2nd PUC Computer science chapter 5 review of c++
Aahwini Esware gowda
 
PPTX
Concept Of C++ Data Types
k v
 
PPT
C++ tutorials
Divyanshu Dubey
 
PDF
Object Oriented Programming Short Notes for Preperation of Exams
MuhammadTalha436
 
PPTX
C_plus_plus
Ralph Weber
 
PPTX
CP 04.pptx
RehmanRasheed3
 
PPTX
Learn c++ Programming Language
Steve Johnson
 
PPTX
Operators
moniammu
 
PPTX
Programming using c++ tool
Abdullah Jan
 
PPTX
UNIT - 1- Ood ddnwkjfnewcsdkjnjkfnskfn.pptx
crazysamarth927
 
PDF
Data types, operators and control structures unit-2.pdf
gurpreetk8199
 
PPT
Key Concepts of C++ computer language.ppt
AjayLobo1
 
Computer science_xii_2016
Ritika sahu
 
Data Handling
Praveen M Jigajinni
 
C cpluplus 2
sanya6900
 
OOPS (object oriented programming) unit 1
AnamikaDhoundiyal
 
Concept of c data types
Manisha Keim
 
Basic concept of c++
shashikant pabari
 
C++ theory
Shyam Khant
 
OOC MODULE1.pptx
1HK19CS090MOHAMMEDSA
 
2nd PUC Computer science chapter 5 review of c++
Aahwini Esware gowda
 
Concept Of C++ Data Types
k v
 
C++ tutorials
Divyanshu Dubey
 
Object Oriented Programming Short Notes for Preperation of Exams
MuhammadTalha436
 
C_plus_plus
Ralph Weber
 
CP 04.pptx
RehmanRasheed3
 
Learn c++ Programming Language
Steve Johnson
 
Operators
moniammu
 
Programming using c++ tool
Abdullah Jan
 
UNIT - 1- Ood ddnwkjfnewcsdkjnjkfnskfn.pptx
crazysamarth927
 
Data types, operators and control structures unit-2.pdf
gurpreetk8199
 
Key Concepts of C++ computer language.ppt
AjayLobo1
 
Ad

More from Dev Chauhan (17)

PDF
GTU induction program report
Dev Chauhan
 
PDF
2 States Book Review
Dev Chauhan
 
PPTX
STACK, LINKED LIST ,AND QUEUE
Dev Chauhan
 
PPTX
NETWORKING AND COMMUNICATION TECHNOLOGIES
Dev Chauhan
 
PPTX
DATABASE MANAGMENT SYSTEM (DBMS) AND SQL
Dev Chauhan
 
PPTX
DATA STRUCTURE CLASS 12 COMPUTER SCIENCE
Dev Chauhan
 
PPTX
BOOLEAN ALGEBRA
Dev Chauhan
 
PPTX
OBJECT ORIENTED PROGRAMING IN C++
Dev Chauhan
 
PPTX
Communication and Network Concepts
Dev Chauhan
 
PPTX
What is bullying
Dev Chauhan
 
PPT
Properties Of Water
Dev Chauhan
 
PPTX
बहुव्रीहि समास
Dev Chauhan
 
PPTX
अव्ययीभाव समास
Dev Chauhan
 
PPTX
तत्पुरुष (विभक्ति, उपपद ऽ नञ्)
Dev Chauhan
 
PPTX
कर्मधारय, द्विगु समास
Dev Chauhan
 
PPTX
द्वन्द्व समास
Dev Chauhan
 
PPTX
Class 10 Farewell Presentation Topic:- Nostalgia
Dev Chauhan
 
GTU induction program report
Dev Chauhan
 
2 States Book Review
Dev Chauhan
 
STACK, LINKED LIST ,AND QUEUE
Dev Chauhan
 
NETWORKING AND COMMUNICATION TECHNOLOGIES
Dev Chauhan
 
DATABASE MANAGMENT SYSTEM (DBMS) AND SQL
Dev Chauhan
 
DATA STRUCTURE CLASS 12 COMPUTER SCIENCE
Dev Chauhan
 
BOOLEAN ALGEBRA
Dev Chauhan
 
OBJECT ORIENTED PROGRAMING IN C++
Dev Chauhan
 
Communication and Network Concepts
Dev Chauhan
 
What is bullying
Dev Chauhan
 
Properties Of Water
Dev Chauhan
 
बहुव्रीहि समास
Dev Chauhan
 
अव्ययीभाव समास
Dev Chauhan
 
तत्पुरुष (विभक्ति, उपपद ऽ नञ्)
Dev Chauhan
 
कर्मधारय, द्विगु समास
Dev Chauhan
 
द्वन्द्व समास
Dev Chauhan
 
Class 10 Farewell Presentation Topic:- Nostalgia
Dev Chauhan
 
Ad

Recently uploaded (20)

PPT
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
PPTX
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
PPTX
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
PPTX
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
PDF
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
PDF
CONCURSO DE POESIA “POETUFAS – PASSOS SUAVES PELO VERSO.pdf
Colégio Santa Teresinha
 
PPTX
How to Handle Salesperson Commision in Odoo 18 Sales
Celine George
 
PPTX
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
PDF
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
PDF
The dynastic history of the Chahmana.pdf
PrachiSontakke5
 
PDF
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
PPTX
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
PPTX
How to Create a PDF Report in Odoo 18 - Odoo Slides
Celine George
 
PPTX
2025 Winter SWAYAM NPTEL & A Student.pptx
Utsav Yagnik
 
PPT
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
PPTX
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
PDF
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
PPTX
STAFF DEVELOPMENT AND WELFARE: MANAGEMENT
PRADEEP ABOTHU
 
PDF
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
PDF
The-Ever-Evolving-World-of-Science (1).pdf/7TH CLASS CURIOSITY /1ST CHAPTER/B...
Sandeep Swamy
 
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
CONCURSO DE POESIA “POETUFAS – PASSOS SUAVES PELO VERSO.pdf
Colégio Santa Teresinha
 
How to Handle Salesperson Commision in Odoo 18 Sales
Celine George
 
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
The dynastic history of the Chahmana.pdf
PrachiSontakke5
 
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
How to Create a PDF Report in Odoo 18 - Odoo Slides
Celine George
 
2025 Winter SWAYAM NPTEL & A Student.pptx
Utsav Yagnik
 
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
STAFF DEVELOPMENT AND WELFARE: MANAGEMENT
PRADEEP ABOTHU
 
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
The-Ever-Evolving-World-of-Science (1).pdf/7TH CLASS CURIOSITY /1ST CHAPTER/B...
Sandeep Swamy
 

BASIC CONCEPTS OF C++ CLASS 12

  • 1. Table of Contents Unit /Chapters Unit-I: Object Oriented Programming in C++ Chapter 1: Revision Tour of Class XI Chapter 2: Classes and Object Chapter 3: Constructor and Destructor Chapter 4: Inheritance Chapter 5: Data File Handling Unit-II : Data Structure Chapter 6: Arrays, Stacks, Queues And Linked List Unit-III : Database Management Systems and SQL Chapter 7: DBMS & Structured Query Language Unit-IV : Boolean Algebra Chapter 8: Boolean Algebra Unit- V : Networking and Communication Technology Chapter 9: Networking and Communication Technology
  • 2. COURSE DESIGN Unit Topic Marks I Object Oriented Programming in C++ 30 II Data Structure 14 III Database Management Systems and SQL 8 IV Boolean Algebra 8 V Networking and Communication Technology 10 TOTAL 70
  • 5. • Unit-I • Objective Oriented Programming in C++ • Revision Tour of Class XI Chapter: 01 • Keywords: Keywords are the certain reserved words that convey a special meaning to the compiler. These are reserve for special purpose and must not be used as identifier name.eg for , if, else , this , do, etc. • Identifiers: Identifiers are programmer defined names given to the various program elements such as variables, functions, arrays, objects, classes, etc.. It may contain digits, letters and underscore, and must begin with a letter or underscore. C++ is case sensitive as it treats upper and lower case letters differently. A keyword can not be used as an identifiers. The following are some valid identifiers: • Pen time580 s2e2r3 _dos _HJI3_JK
  • 6. • Data Types in C++: Data types are means to identify the types of data and associated operations of handling it. Data types in C++ are of two types: • 1. Fundamental or Built-in data types: These data types are already known to compiler. These are the data types those are not composed of other data types. There are following fundamental data types in C++: • (i) int data type (for integer) (ii) char data type (for characters) • (iii) float data type (for floating point numbers) (iv) double data type • Data Type Modifiers: There are following four data type modifiers in C++ , which may be used to modify the fundamental data types to fit various situations more precisely: • (i) signed (ii) unsigned (iii) long (iv) short
  • 7. • Variables: A named memory location, whose contains can be changed with in program execution is known as variable. OR • A variable is an identifier that denotes a storage location, which contains can be varied during program execution. • Declaration of Variables: Syntax for variable declaration is: • datatypes variable_name1, variable_name2, variable_name3,……………. ; • We can also initialize a variable at the time of declaration by using following syntax: • datatypes variable_name = value; • In C++ both the declaration and initialization of a variable can be done simultaniouly at the place where the variable is used first time this feature is known as dynamic initialization. e.g., • float avg; • avg = sum/count; • then above two statements can be combined in to one as follows: • float avg = sum/count;
  • 8. • Constant: A named memory location, whose contains cannot be changed with in program execution is known as constant. OR • A constant is an identifier that denotes a storage location, which contains cannot be varied during program execution. • Syntax for constant declaration is: • const datatypes constant_name = value ; • e.g., const float pi = 3,14f ;
  • 9. • Conditional operator ( ? : ): The conditional operator (? :) is a ternary operator i.e., it require three operands. The general form of conditional operator is: • expression1? expression2: expression3 ; Where expression1 is a logical expression , which is either true or false. • If expression1 evaluates to true i.e., 1, then the value of whole expression is the value of expression2, otherwise, the value of the whole expression is the value of expression3. For example • min = a<b? a : b ;
  • 10. • Type Conversion: The process of converting one predefined data type into another is called type conversion. • C++ facilitates the type conversion in two forms: • (i) Implicit type conversion:- An implicit type conversion is a conversion performed by the compiler without programmer’s intervention. An implicit conversion is applied generally whenever different data types are intermixed in an expression. The C++ compiler converts all operands upto the data type of the largest data type’s operand, which is called type promotion. • (ii) Explicit type conversion :- An explicit type conversion is user-defined that forces an expression to be of specific data type. • Type Casting:- The explicit conversion of an operand to a specific type is called type casting. • Type Casting Operator - (type) :-Type casting operators allow you to convert a data item of a given type to another data type. To do so , the expression or identifier must be preceded by the name of the desired data type , enclosed in parentheses . i. e., • (data type) expression • Where data type is a valid C++ data type to which the conversion is to be done. For example , to make sure that the expression (x+y/2) evaluates to type float , write it as: • (float) (x+y/2)
  • 11.  Some important Syntax in C++: 1. if Statement if ( < conditional expression > ) { < statement-1 or block-1>; // statements to be executed when conditional expression is true. } [ else { < statement-2 or block-2>; // statements to be executed when conditional expression is false. } ]
  • 13. 3. switch Statement :- switch (expression/variable) { case value_1: statement -1; break; case value_2: statement -2; break; : : case value_n: statement -n; break; [ default: statement -m ] }
  • 14. 4. The for Loop: for(initialization_expression(s); loop_Condition; update_expression) { Body of loop } 5. while Loop: while (loop_condition) { Loop_body } 6. do-while loop: do { Loop_body }while (loop_condition);
  • 15. The Working of Break Statement
  • 17. 2. User-defined function :- The functions which are defined by user for a specific purpose is known as user-defined function. For using a user-defined function it is required, first define it and then using. Declaration of user-defined Function: Return_type function_name(List of formal parameters) { Body of the function } Calling a Function:- When a function is called then a list of actual parameters is supplied that should match with formal parameter list in number, type and order of arguments. Syntax for calling a function is: function_name ( list of actual parameters ); e.g.,
  • 18. #include <iostream> int addition (int a, int b) { int r; r=a+b; return (r); } void main ( ) { int z ; z = addition (5,3); cout<< "The result is " << z; } The result is 8 Call by Value (Passing by value) :- The call by value method of passing arguments to a function copies the value of actual parameters into the formal parameters , that is, the function creates its own copy of argument values and then use them, hence any chance made in the parameters in function will not reflect on actual parameters . The above given program is an example of call by value. Call by Reference ( Passing by Reference) :- The call by reference method uses a different mechanism. In place of passing value to the function being called , a reference to the original variable is passed . This means that in call by reference method, the called function does not create its own copy of original values , rather, its refers to the original values only by different names i.e., reference . thus the called function works the original data and any changes are reflected to the original values.
  • 20.  Scope of Identifier :- The part of program in which an identifier can be accessed is known as scope of that identifier. There are four kinds of scopes in C++ (i) Local Scope :- An identifier declare in a block ( { } ) is local to that block and can be used only in it. (ii) Function Scope :- The identifier declare in the outermost block of a function have function scope. (iii) File Scope ( Global Scope) :- An identifier has file scope or global scope if it is declared outside all blocks i.e., it can be used in all blocks and functions. (iv) Class Scope :- A name of the class member has class scope and is local to its class.
  • 22.  Defining Structure :- struct< Name of Structure > { <datatype>< data-member 1>; <datatype>< data-member 2>; <datatype>< data-member 3>; … … <datatype>< data-member n>; } ; Declaring Structure Variable :- struct< Name of Structure > { <datatype>< data-member 1>; <datatype>< data-member 2>; <datatype>< data-member 3>; … … <datatype>< data-member n>; } var1, var2,….., varn ; We can declare the structure type variables separately (after defining of structure) using following syntax: Structure_name var1, var2, …… ….., var_n; Accessing Structure Elements :- To access structure element , dot operator is used. It is denoted by (.). The general form of accessing structure element is : Structure_Variable_Name.element_name
  • 23.  Pointer:- Pointer is a variable that holds a memory address of another variable of same type. Declaration and Initialization of Pointers : Syntax : Datatype *variable_name; e.g., int *p; float *p1; char *c; Two special unary operator * and & are used with pointers. The & is a unary operator that returns the memory address of its operand. e.g., int a = 10; int *p; p = &a; Pointer arithmetic: Two arithmetic operations, addition and subtraction, may be performed on pointers. When you add 1 to a pointer, you are actually adding the size of whatever the pointer is pointing at. That is, each time a pointer is incremented by 1, it points to the memory location of the next element of its base type. e.g. int *p; p++; If current address of p is 1000, then p++ statement will increase p to 1002, not 1001. Adding 1 to a pointer actually adds the size of pointer’s base type. Base address : A pointer holds the address of the very first memory location of array where it is pointing to. The address of the first memory location of array is known as BASE ADDRESS. Dynamic Allocation Operators : C++ dynamic allocation operators allocate memory from the free store/heap/pool, the pool of unallocated heap memory provided to the program. C++ defines two operators new and delete that perform the task of allocating and freeing memory during runtime. Pointers and Arrays : C++ treats the name of an array as constant pointer which contains base address i.e address of first memory location of array.
  • 24.  typedef :- The typedef keyword allows to create alias for data types. the syntax is: typedef existing_data_type new_name ; e.g. typedef int num;  #define Preprocessor Directive: The # define directive creates symbolic constant, constants that are represent as macros. Macros: Macros are preprocessor directive created using # define that serve as symbolic constants. They are created to simplify and reduce the amount of repetitive coding e.g.1 #define PI 3.14 Here PI is defined as a macro. It will replace 3.14 in place of PI throughout the program. e.g. 2 #define max (a, b) a>b? a: b Defines the macro max, taking two arguments a and b. This macro may be called like any function. Therefore, after preprocessing A = max(x, y); Becomes A = x>y?x :y ;
  • 25.  Function Overloading: Function overloading is the process of defining and using functions with same name having different argument list and/or different return types. These functions are differentiated during the calling process by the number, order and types of arguments passed to these functions. Example: int Add (int ,int) ; double Add (double ,double) ; float Add (int ,float) ;
  • 26. Short Answer Type Questions (2-Marks) 1. Define Macro with suitable example. 2. Explain in brief the purpose of function prototype with the help of a suitable example. 3. What is the difference between Global Variable and Local Variable? 4. What is the difference between Object Oriented Programming and Procedural Programming? 5. What is the difference between Global Variable and Local Variable? Also, give a suitable C++ code to illustrate both. 6. Differentiate between ordinary function and member functions in C++. Explain with an example. 7. What is the difference between call by reference and call by value with respect to memory allocation? Give a suitable example to illustrate using C++ code. 8. What is the difference between actual and formal parameter ? Give a suitable example to illustrate using a C++ code. 9. Differentiate between a Logical Error and Syntax Error. Also give suitable examples of each in C++. 10. Find the correct identifiers out of the following, which can be used for naming variable, constants or functions in a C++ program : While, for, Float, new, 2ndName, A%B, Amount2, _Counter 11. Out of the following, find those identifiers, which cannot be used for naming Variable, Constants or Functions in a C++ program : _Cost, Price*Qty, float, Switch, Address One, Delete, Number12, do 12. Find the correct identifiers out of the following, which can be used for naming Variable, Constants or Functions in a C++ program : For, while, INT, NeW, delete, 1stName, Add+Subtract, name1