Lectures 1 2
Lectures 1 2
Programming
Instructor: Dr.M Kiran Reddy, Assistant Professor, CSE
Spring 2025
Prerequisites
Schedule
MODULE-1:
Introduction, POP vs OOP, Benefits of OOPs, C++ concepts: Intro, preprocessors, namespace, syntax, input/output, comments, keywords
and identifiers, variables-literals-consonants, data types, type modifiers, operators, relational and logical operators, conditional statements,
loops, functions, arrays & strings, pointers and references, structures & enumerations.
MODULE-2:
Class and objects, Constructors and destructors, Access specifiers, Static Data Members, Static Member Functions, Friend Functions,
Arrays of objects, Objects as function arguments, Encapsulation, Abstraction, Inheritance: types (Single, multiple, multilevel, hierarchical,
Hybrid), Overriding inherited methods, Polymorphism: static vs dynamic, Operator overloading (ad hoc polymorphism), Method overload
(compile time polymorphism), and Method overriding (run-time polymorphism).
MODULE-3:
Introduction to Memory management, new operator and delete operator, dynamic memory allocation in arrays. Memory Allocation for
Objects, Pointers to objects, ,Pointers to Derived Classes. File handling, Exception handling, templates, standard template library -
containers, iterators, algorithms. Array of vectors, Vector of vectors.
Text/Reference Books
The high-level programming languages are broadly categorized into two categories:
POP OOP
Program divided into small parts called Program divided into small parts called objects
functions
Follows top-down approach Follows bottom-up approach
Does not support polymorphism Method overloading and overriding are possible
#include <iostream>
#define PI 3.14
using namespace std;
int main()
{
int radius = 6; // Intialize radius
double c = 2*PI*radius; // Calculate the circumference of the circle
cout << "The circumference of the circle is:" << c << endl; // Print the circumference
return 0;
}
Execution of C++ code
Source code
(.c file)
Preprocessor
(expanded code *.i file)
Compiler
(Assembly code *.s file)
Linker
Executable (*.exe)
Loader
Preprocessor
Pre-processing phase includes:
1. Removes the comments and unnecessary white-spaces from the program.
2. Expands the Preprocessor directives such as macros, conditional compilations, expansion of
included files.
3. In principle, a clean C++ source module - without any “#” directives, comments is obtained as
output.
4. This step generates an intermediate file example.i, which can be obtained using the code
• The converted code is stored in example.o file i.e. example.s -> example.o
• Object files from this process can be placed in archives called static libraries
for later use; you don’t have to recompile all your source files if you change
only one file.
g++ -c example.s
Linker
• The linker is responsible for creating a coordinated and functional executable from multiple
object files, ensuring that all parts of the program can work together seamlessly.
• The main functions of linker are : (i) Combining object files, (ii) Symbol resolution, (iii)
Address Binding, (iv) Relocation and (v) Handling libraries.
• Generates an executable file that contains binary code carrying instructions for a CPU to run
a program. Example.o to out.exe
g++ example.cpp
g++ example.cpp -o out1 (to get executable file with custom name ‘out1’)
Loader
• The loader is a part of operating system (OS) and its main function is to load the executable file
into memory, allocate memory space for the program code and data, and set up the initial state of
the program.
• The loader operates at run-time and loads the program into the main memory for execution of
that program.
• It performs the process of address binding, which involves associating symbolic addresses used in
the program with actual memory addresses. This can include absolute, relative, or dynamic
addressing, ensuring that the program can access its required resources correctly.
• The loader detects errors such as insufficient memory, incompatible executable file formats, and
missing dynamic libraries.
• Initializes the program counter to point to the entry point (usually the “main” function) of the
program.
• After loading: