Professional Documents
Culture Documents
Session 1.8
Session 1.8
MODULE 1 1
20CS411 – DATA STRUCTURES USING C++
MODULE – 1
C++ PROGRAMMING
An overview of C++ - Difference between procedure and object oriented
programming language, Data Types, Variables, Operators, Expressions
and Statements-Functions and Arrays- C++ Class Overview- Class
Definition, Objects, Class Members, Access Control, Constructors and
destructors, parameter passing methods, Inline functions, static class
members, this pointer, friend functions, dynamic memory allocation and
deallocation (new and delete) - Inheritance basics, base and derived
classes, inheritance types, runtime polymorphism using virtual functions,
abstract classes - Generic Programming- Function and class templates.
MODULE 1 2
20CS411 – DATA STRUCTURES USING C++
1.4 Functions
1.5 Arrays
1.6 C++ Class Overview- Class Definition, Objects, Class Members
MODULE 1 3
20CS411 – DATA STRUCTURES USING C++
and delete)
1.11 Inheritance basics, base and derived classes, inheritance types
MODULE 1 4
20CS411 – DATA STRUCTURES USING C++
Function
• Functions are building blocks of the programs
• It makes the programs more modular, easy to read and
manage.
• All C++ programs must contain the function main().
• The execution of the program starts from the function
main( )
MODULE 1 5
20CS411 – DATA STRUCTURES USING C++
MODULE 1 6
20CS411 – DATA STRUCTURES USING C++
MODULE 1 7
20CS411 – DATA STRUCTURES USING C++
MODULE 1 8
20CS411 – DATA STRUCTURES USING C++
MODULE 1 9
20CS411 – DATA STRUCTURES USING C++
Call by Value
• This method uses in-mode semantics.
• Passing the argument to the function at calling position.
• In call by value, original value can not be changed or modified.
#include <iostream> int main()
using namespace std; {
int a =10;
void fun(int a) fun(a);
{ cout<<"Value of A:
a=20; "<<a<<endl;
} return 0;
}
MODULE 1 10
20CS411 – DATA STRUCTURES USING C++
MODULE 1 11
20CS411 – DATA STRUCTURES USING C++
MODULE 1 13
20CS411 – DATA STRUCTURES USING C++
MODULE 1 14
20CS411 – DATA STRUCTURES USING C++
Pass by reference
• Pass by reference uses in/out-
mode semantics.
• Pass the reference variable of
the argument, so for updating
it, the actual value will be
updated.
• Only at the function definition,
put & before variable name
MODULE 1 16
20CS411 – DATA STRUCTURES USING C++
Pass by Result
• This method uses out-mode semantics.
• The control is transferred back to the caller, the value of the
formal parameter is transmitted back to the actual
parameter.
• This method is sometimes called call by result.
MODULE 1 18
20CS411 – DATA STRUCTURES USING C++
Syntax:
inline function-header
{
Function body
}
MODULE 1 19
20CS411 – DATA STRUCTURES USING C++
MODULE 1 20
20CS411 – DATA STRUCTURES USING C++
MODULE 1 21
20CS411 – DATA STRUCTURES USING C++