Dr. Bhatia offers a masterfully structured academic overview that simplifies C++ for the exam-room, though it occasionally trades deep engineering nuance for textbook clarity. It is an excellent pedagogical tool that prioritizes theoretical pillars over the messy pragmatism of real-world software development.
Deep Dive
Voraussetzung
- Keine Daten verfügbar.
Nächste Schritte
- Keine Daten verfügbar.
Deep Dive
C++Hinzugefügt:
Right now we are 21. So, should we start we wait for a while or we start?
So, tomorrow we have examination so we start today.
So, we try to complete each and every topic but still if something is left let me know from the chat window so that I cover so that I cover it, okay?
Okay, so we start the class now, okay?
So, go we have very less time to worry about the nation.
Or paper for camera here, that is a target.
Okay.
Uh let's start with the basic fundamental of programming.
We will cover everything, don't worry.
Important topics you better to know in this one. don't worry.
So, the basic programming construct if we start the programming so we have at the start hash include iostream.h.
It is a header file that is preprocessed as we know.
And preprocessed means it is already compiled in nature.
We have a return type of the main function that is int.
And then we print anything on a console window using std::cout.
iostream "Hello world" is printed to your console.
Okay?
So, as I tell you that uh iostream is basically your header files and cin and cout are the uh used for the input and output. Okay?
So, if you see my in my first program this is very basic program in which we have we take a number from the user and display it.
This program is for those students who are not attending any class. Okay? And every point of the syllabus is to be covered in this session. So, please So, please be there and listen it carefully. If you have any doubt, please give it on chat chat box. I will explain it.
So, in this program, if you see this program, I am taking input a number from the user through an input stream.
And num is here is a variable. So, many students having doubt and if we ask what is variable, so variable is basically a temporary memory assigned here to num. And which takes an input from the user in C out line, line number 43, 44, in C out, we just display the output to the screen.
Expression enter a number and the number is taken in the C in. And after that it will be displayed like C out, you entered a number.
So, in a similar manner, if I ask you to write a code in C++ for the addition of two numbers. Suppose we take addition of two numbers.
So, int main, int num1, num2, C out, enter a two number, in C in, instead of num, we are mentioning number num1, then again input stream, num2, and perform the addition of a two number.
Don't think I am I am starting from the scratch. Reason behind is that many students are there who don't have a basic knowledge about C++. But you don't worry, I will cover all the points of your syllabus. You may take a syllabus in your hand and side by side, you just compare the topic is completed or not and you get a notes also for that.
The next topic is after the basic construct of C++, there is a data types.
So, in C++, you have different data types like float, int, double, character, decimal.
So, we are taking a different example of that.
Like const float pi 3.14. Generally, when we are finding the area of circle, many places we are using the value of pi that is 3.14. And it is a constant value that we have mentioned here the const keyword.
So, if we mention the const with any variable, it means this variable can't be changed later.
Similarly, we are taking another variable of integer type that is age getting a value 25.
Then, grade.
Grade generally A, B, C.
So, they are the character type, so mentioned as a character data character is a data type. Grade is a variable name and A is basically a single character.
So, always a single character is taken inside a single quotes. Please be remember.
Students are doing a minor mistakes.
So, single character will be taken a a character is taken as a single inside a single quotes, while the string is taken inside a double quotes. So, be remember this. So, it is behind the data type, variable, and constant. So, data types are int, float, char.
And variables are I already tell you variable is a small memory area allocated in a RAM to store the temporary value. Okay?
Constant, if we add a const keyword with any variable, so this its value can't be changed later. Okay?
Next topic is control flow.
So, inside a control flow, we generally write a program where there is a continuous loop is there. Like like the multiplication of a number or you want to display or write a table.
Okay? So, you know that the table is starts from uh if you take example 2 * 1 = 2 until we are writing 2 * 10 = 20.
So, what happened inside this?
There is one operation that is a multiply operation performed in a on a variables.
On a two numbers, you can say, because we take a number in a variable, so I I say variable, okay? So, in that case where there's a repetition of operation is performed, we generally use for loop, while loop, do while loop.
So, for loop having if you see, we have a for loop here. For loop having initialization, this is called initialization, okay?
Comparison, and increment and decrement.
Inside a for loop. So, we have three things.
From where to start, where to end, that is representation by represented by a condition, and increment and decrement operator.
Why? In while loop, if you see, the comparison initialization is outside.
With the while, we have a condition, and inside it, we have an increment or decrement.
In the case of a do while, initialization is performed at the start, same as a while loop, but condition check is performed at the end.
So, if you are confident with a code, and you know everything about the code, we prefer for loop.
If you are not confident with our code, like we want that once it at least once it runs, so that we can see the output, so we use do while loop.
So, many times in examination also, people will ask at what time what kind of loop you prefer, and give its example. So, for loop, when you are very much confident about from where to start, where to end, how much increment and decrement is required, and you are confident about your code, then you use for loop.
Otherwise, you are use uh uh do while loop.
In while loop generally what happened?
In while loop generally people uh forget to increment decrement at many times it will seen in a programming that it will goes to infinite loop, okay? So, it is a demerit of while loop.
So, looping is somewhere your condition that is required in a two variable and operation is performed uh a number of times, then we apply a looping concept.
After that we have a memory management that is array and pointer.
So, what is array? The definition of array is array is a continuous memory location >> [snorts] >> allocated to a similar data type. If you see my definition, array stores multiple elements of same type in a contiguous memory.
So, array can be a one dimensional, two dimensional array array is dependent on indexing purpose. So, index is starting from the zero.
And when we deal with a memory management concept, suppose you want to take a memory from a heap at the run time, so you use new and delete operators. It is for the memory management. The new operator is to allocate the memory. Delete operator is to allocate the memory. So, in my example, uh first we declare a one dimensional array here at the line number 87.
Array name is ARR and if you see 1 2 3 4 5 is allocated and it is a integer type of in array the index is start from the zero and add and till n minus 1.
And if you want to write a two dimensional array, so the the way to write a two dimensional array generally two dimensional or three dimensional are basically the matrices.
So, we have 1 2 inside a curly braces 3 4 and outside also curly braces and semicolon. So, please be remember row and columns are mentioned in this manner.
Similarly for a dynamic allocation as I said new operator is used to allocate the memory. So, int pointer P is equal to new int 10. So, P is a pointer variable which is getting a dynamic dynamic memory of integer or value or 10 integer value and delete the pointer P value. So, till what is array and how the memory is located we completed.
Next topic of our syllabus is in the first unit because first unit is just the overview. That's why I just go through it.
The next topic is function and recursion. The function are the some code that we can reuse. Okay?
And we pass some value to it. It performs some operation and gives some uh some result outcomes. So, that is a function. The function can be defined as a separate module that is assigned or written in such a manner that it will it will take uh input, perform some operation and returns the output.
Okay?
So, function allowed like uh we have a recursion also. A recursion is a concept in which the function call itself.
It will It will help us to reduce the co- code.
And behind the function there is a memory concept that is stack will work.
Okay?
And recursion is calling the function by itself. Now, we come to the next topic that is object-oriented programming. Uh suppose you know, object-oriented programming there are some concepts like objects, combining attributes, functionalities like methods, encapsulation, that is a bind data and function, constructor that is used to initialize the memory. But, we go through it one by one and that's we will complete it. Don't worry.
So, we create one class that is box.
In this box class we have a field that is private in nature, that is width.
And inside a public, if you see, the class name is box and inside we have a box with a parameter int w.
It is a constructor. So, constructor used to initialize the member variable.
And destructor is used to destroy, means taking a memory out.
Similarly, you can if you want to display the value, so we have So, class is basically consists of member variable and member function. It is a blueprint. Class is basically consists of member variable and member function, and it is a blueprint, okay?
So, now I'm going to show you one uh advanced topic, that is uh operators.
I have a friend function. So, friend functions are special kind of function that are basically associated with your We declare inside a class, and it will access the private member function of that class, okay?
And operator overloading, in which we give a new definition to our operators.
And the last topic for the first unit is what is the difference between union and structure? What is union and what is structure? Okay?
So, union is something is a special kind of you can say a data structure or a type of declaration where variables are basically shared the memory. So, union generally written as you take a keyword union, and then union name here we are taking data as a union name and two variables are there. One is int I, other is char character C.
Okay?
So, in union generally, we share the memory.
The highest one which is like a from int or char if we compare the int takes larger bytes as compared to your character.
So, that memory is allocated to the memory that is allocated to I is the final one because in union, the max size of the member memory will be allocated. Okay? While in structure, each of the component or each of the variable will acquire their own memory.
Okay?
So, structure is faster than union.
Please be remember because difference is very important. Structure is faster Structure is faster than union.
And second, union If you want to fetch the data, so in structure, you will get the all the data at the once. So, in union, you have to take it in one by one. So, the first of the important question that you asked me, what is the difference between union and structure and how it is to be declared? It is one of the important question. And this link is given here in my notes that will be shared with you. So, after the class, you will just copy this link and you will get the difference between structure and union. Okay?
Now, the next part is I will take your two or three minutes so that you will understand the concept of class and objects so we move to the second module.
Okay? So, please I can teach you code in Python in just 30 days even if you've never written a single line of code before. How? Simple.
In my 30-day Python using People hear the word class and they think of school.
People hear the word object and they think something physical.
But in programming a class is not a thing and an object is not an idea.
Let's fix that.
>> [music] >> Meet Classy.
Classy is not a real thing.
Classy is a blueprint, a plan, a description.
Classy tells us what something should look like and what it can do.
In object-oriented programming, [music] we call this idea a class.
Now meet Ollie.
Ollie is real.
Ollie is built from Classy.
Ollie has a shape, a [snorts] color, a location. [music] Ollie can exist.
Classy cannot.
In object-oriented programming, we call this idea an object. [music] Classy doesn't make just one Ollie.
Classy can make many Ollie's.
Each Ollie is real.
Each Ollie exists on its own.
But they all come from the same Classy.
A class is like a blueprint.
An object is like a building.
You can design one blueprint and build many buildings from it.
But without the blueprint the building cannot exist.
An object is not a copy of a class.
You don't copy a blueprint.
You use it to build.
Classy [music] stays the same.
Ollie is created.
That difference matters.
Let's look at real life.
Think about a mobile phone.
Mobile is the idea.
The design, the template, that is the class.
Now, your mobile, your father's mobile, your mother's mobile, each one is real.
Each one is an object.
This idea [music] is everywhere.
Think about a car.
Car is the idea.
Your car, a taxi, a neighbor's [music] car.
Different cars, same idea.
Think about a house.
A plan, a design, [music] apartments, homes, villas.
One class, many objects.
So, remember [music] this.
A class is a blueprint.
An object is a real thing made from that blueprint.
One class, many objects.
Never the other way around.
Let's check something.
Which one is real?
The blueprint [music] or the thing built from it?
The object is real.
The class is the idea.
But here's the next question.
If Ollie is built from Classy, how does Ollie know what it has and what it can do?
That's where properties and methods come in.
In the next episode, you'll learn what properties and methods really are.
Not as definite So, hopefully before before starting the class and object, I want to discuss this one because this is very important concept and the case studies are generally based on this kind of basic understanding.
So, you can easily solve it. If you understand the concept, you can easily solve any kind of case studies. So, as you people ask me important questions, so I tell you what is the difference between union and structure is one of the important question. Maybe they ask it separately.
Okay.
And rest things, what are data types, what all data types make a constant. Such kind of things are very important. And side by side as the modules are proceed, we will discuss other concepts as well. Okay.
So, in module two, we have a first concept that is type conversion.
So, we have a two type of conversion.
One is called implicit, that is called automatic. And other is explicit, that is called explicit casting.
So, in automatic casting means the larger the in the in the larger one, the smaller one can be easily adjust. So, my my the sense we have int and float.
So, if we have a variable that is that is that contains a integer value, so that can be easily assigned to float one because the float having a larger size as compared to int. So, you don't need any special kind of keywords to perform this. So, implicit conversion is performed by the compiler without programmer intervention. It it will do by itself. It typically happens when the moving from the smaller data type to a larger one. So, easily can be accommodated. But in explicit one, perform manually by the programmer using the cast operator. You have to mention in this case, the reverse is happened.
Uh A larger value can be assigned to a smaller variable. Uh like a double value assigned to a integer. So, the simple example is if you have a a 4 kg bucket a bucket in your hand and 2 kg is basically the material. So, the 2 kg material can be easily taken in a 4-kg 4-kg bucket. That is called implicit. It can be easily done.
But the reverse of that, if you have a 2-kg bucket and you want to uh add an object of 4 kg, so it will not easy. So, you have to be explicitly perform something uh in order to hold it. So, that that is basically your explicit conversion. So, this question is very important. What is a type conversion? What is implicit conversion?
What is explicit conversion?
Next important topic is inline function.
So, inline is very important as for the examination point of view.
So, inline means uh sometime it happens uh that we want that the compiler will not jump because every time when the function is called the compiler will jump and search for that function name and perform the task.
If you want that because it will take time. So, in order to optimize it, what happened? We generally write a keyword outside the function and we request compiler that uh that the with the function definition there is a declaration is available.
Please don't jump. So, it will eliminate the overhead of the function. So, by putting a inline we perform the optimization, but it is a request. It is not uh it is not compulsion to our compiler.
It is a request performed by the compiler that please don't jump and uh eliminate the overhead. Okay? The next very important topic is string class. So, we have a string class like string header. We use a string uh as a header file and various string operations are performed using this uh string class file like concatenation, uh append, finding length of the string, size of the string that can be easily performed using this string class.
So, already our video is shared with you uh regarding the classes and object. I thank Dr. Pradeep Bhatia sir for that. So, what is class?
Class is a blueprint.
And you find a data type. And this data type is a user defined data type. And user is a end user.
And user is someone for for the person for for whom we are creating the software.
Okay. Suppose you want to automate the library. You go to the library and you visited the library and you you mentioned different instance library.
That is basically the class. But when you actual perform that task, that is called the instance of a class.
The existence actual existence of the class is called the object. In our only example, it is there. Okay.
So, in our case, we create a class my class. And having public variable that is member my num.
And void display is a function member function.
So, class is created. Please be remember after the class end, generally student do a mistake that they are not putting the semicolon. After the end of the class, if you see, you always write the semicolon. Okay.
And in the main we clear we create an object of the class my class. And we are calling object.my num and assign the value 10 to this. Okay.
So, now we move ahead.
So, this is one of the These classes are those students who want to learn each and every topic in a short while.
So, that they can perform in examination.
>> [snorts] >> So, basic understanding to advance so that you can solve any case study. You can understand every >> I got one challenge for you. Try whisper for once. One time. And I promise you'll understand why I have >> [music] >> So, next topic is >> If I tell you about a person, their name, their age, that tells you what they are.
But, if I tell you they can walk, they can talk, they can run, that tells you what they can do.
In programming, these two ideas are never the same.
Back in Codeville, we already met Ollie, a real object built from a class.
But, Ollie is more than just a shape.
Ollie knows things.
>> [music] >> Ollie knows his color.
Ollie knows where he is.
These are called properties.
Properties describe an object.
They tell us what it is.
They don't do anything. [music] But, Ollie can also do things.
Ollie can move.
Ollie can speak.
Ollie can react.
These are called methods.
Methods are actions.
They make things happen.
Here's a common mistake.
Color is not an action.
Position is not an action.
Running is an action.
Speaking is an action.
Properties [music] describe.
Methods perform.
Ollie's color can't change by itself.
Ollie's position can't change by itself.
Properties don't act.
They wait.
So, remember this.
Properties [snorts] are what an object knows.
Methods are what an object does.
Every object has both.
But, they play very different roles.
If Ollie moves and his position changes, what did the action?
And what changed?
The method [music] acted.
The property changed.
When you separate knowledge from action, your programs become easier to understand, easier to change, and easier to [music] grow.
But before an object can be used, it has to be created. It has to start life with the right values in the right state.
That beginning moment is called a constructor.
>> [music] >> Imagine doing the same work again and again and again.
Every time you build something new, you copy the same behavior, paste it again, fix it again.
Okay. So, from the module three So, we know that what is basic things, what are abstraction, what are encapsulation, inheritance, polymorphism. They are basic four core pillar of Hello.
Hello.
Hello.
So, the next important question is what are the basic pillars of object-oriented programming? This may be coming 10 marks. This may be coming the higher one or anyone. This question must be there in examination.
So, the basic four pillars of a programming is abstraction, encapsulation, inheritance, and polymorphism.
What is abstraction is abstraction is hiding the things, giving the detail as much as necessary for the end user. It's called abstraction.
Second is encapsulation. Encapsulation is binding of member variable and member function together so that outside function can't access it.
Outside means other than the member function can't access it.
Third topic is inheritance. Inheritance is basically a biological term in which the child class inherited from the parent class and will acquire its protected and public member functions or member variable.
And polymorphism means a same function behave differently depending upon the call. Okay, I just give you a view of these four pillars. It may be they will ask in a short question.
Explain about the four pillars of oops.
So, abstraction, encapsulation, inheritance, and polymorphism. Somewhere in some books they are writing class and object also.
But you may write it. If you want to make your answer a lengthy one, you can use an object also there. There's no issue. But the basic four pillars are abstraction, encapsulation, inheritance, and polymorphism.
Okay.
The important practice data hiding that is performed through encapsulation and that to acquire encapsulation we have some kind of access specifier that is public, private, and protected. Okay.
So, through these access specifiers, we can hide the data from the outside, okay?
Purpose, it ensures the correctness of data and prevent accidental manipulation. Like there is an example we are taking in the first slide. In our audio player class, you might hide the volume variable so it can be accessed, okay? So there are many places where we can perform the concept of data hiding.
So one YouTube video is there.
After completion of my lecture, I will share this notes to with you so you people can go that video and get a knowledge about it.
Next is member function. So member functions are the functionalities or or operations that can be performed on an object. So so we apply the concept of access specifier.
Generally the good coding practice is member function must be uh public in nature while the member variable are generally private in nature. So we prefer this kind of good practices of coding that member function must be public and member variable are private in nature.
So when we are writing a code, if you see we have two important concepts also now. This is very important because every time when I encounter an important topic that will be useful for you in the examination, I will cover it by saying it is important one. So it is it is a hint to you that if you practice it and you learn that topic, it will give you a benefit in examination.
So there are two type of special kind of function. One is called constructor, other is called destructor.
Constructor are used to initialize the object while the destructor are used to taking a memory out of deallocate the memory, you can say.
So while any object is created, a constructor is fired, okay? And whatever the member variable are there they it will initialize it.
Okay? So that there is no garbage value there. And destructor because you allocate the memory and memory must be free when the task is completed, so destructor will do the deallocation task for us.
Some in some programming language we are also using getter and setter also.
So constructor is very important constructor and destructor.
Next important topic is your memory allocation.
So generally when we are writing our normal variable, it will get a memory from the stack. Okay? And when we use a new operator we are getting the memory from the heap. Please be remember because uh in a short question also they may ask uh while the dynamic memory allocation and the new operator is used, which part of memory will be de- from which part the memory will be allocated?
The memory allocated from the heap section. While the normal variable uh the memory is allocated through a stack. And if you perform any kind of like memory is allocated and you want to know how much memory is allocated, so you use a size of operator. So these three points are very important if the question question coming from the memory allocation.
Uh stack dynamic memory from heap and deallocation memory and size of operator to get the size that is allocated.
The another important topic is static member or static object. The static member whenever you use a keyword static so it means a single variable will be shared by a multiple object.
If we write a static keyword with any data or a function, it means uh uh it means that its single instance its single occurrence will be shared with multiple objects. So this one is very important for the interview point of view.
So as I tell you the constructor is very important.
So, let's complete the constructor.
A constructor is a function with the same name as that of the class. Okay?
Automatically, it will be fired once the object is created.
There are three type of constructor because if the question is question is bigger one, then you have to uh with respect to marks, you have to write. So, the types of constructor they are three types of constructor. One is default constructor, other is parameterized constructor, third is copy constructor.
Default constructor having no parameter and it initialize object with a default values. So, the default value for the integer is zero and for any character is uh null value. Okay? So, we remember this one. Default constructor having no parameter and will be initialized default by default values. So, based on the integer, float, or a cap, the value will be assigned. Similarly, parameterized constructor, if you know that what value should be assigned, so, you just give the argument to the constructor. And that argument value will be assigned to your member variables. Okay? So, that is called parameterized constructor. So, for example, while you are going to a uh perform, so he or she will tell you that please see the meter.
So, they will initialize with zero.
Okay? So, that is called the default constructor.
But, when you pick a Ola cab or something and you are So, you see that there is minimum amount 15 rupees or 12 rupees is there, they will deduct it always. So, that minimum amount 12 or 15 is basically the value that is initialized its object that object that what that is also a software. The the bill calculated Ola Ola or Uber or there there is some software behind it. So, parameterized through parameterized constructor, we initialize that object. Okay?
Next is copy constructor. It is used to copy properties is a one existing object object into a new object. Whenever you copy one object to another object, so we follow the copy constructor concept.
Okay? So, these three are very important. What is constructor or types of constructor? You people are asking you know what are the important questions. So, this is one of the important question.
What is constructor and the type of Opposite of constructor is destructor.
So, destructor as a name suggests, it destroys the object and freeing the memory that is assigned.
So, its name is same as that of the your class name but with the tilde sign.
Okay? We remember this. And in Java it is automatically called but in C++ we have to write it. Okay?
So, in memory management the compiler handles can handle destructor for simple data types. Okay?
So, this is very important the difference between constructor and destructor.
So, constructor purpose is to initialize an object while the destructor purpose is to destroy an object. Parameters Definitely constructor in constructor you give the parameters. Yeah, overloading is allowed it but no parameter is passing in a destructor.
And how we mention it? Uh naming with the class name. If they give the constructor having same name that of the class while the destructor having a tilde sign. If you see here we are missing this tilde sign. The class name but that is a destructor.
Uh timing timing when it is to be called called at object creation for the constructor, called at object destruction. So, this is basically a basic concept of constructor and destructor. This is very important concept.
You have to be master on that.
Next is polymorphism.
In polymorphism as we said that the same Okay, I will try this video again and again. Please don't mind because it will makes your case study easier because you understand the concept by your heart. If you visualize it what it is, so you can easily solve the case study. That's why I'm running these videos. I I don't want to run but still because I know that it will make your concept much more clear for tomorrow examination. So, that's why I'm just running these videos so that you can easily understand by your heart and can apply to a case study.
So, please be cooperative with me.
We are about to level up.
Level up.
Imagine giving the same instruction to different people.
You say, "Move."
One person walks.
Another runs.
Another rolls.
Same instruction, different behavior.
That idea is called polymorphism.
Back in Codeville, we already know about parents and children.
>> [music] >> Children inherit shared behavior.
But inheritance alone doesn't [music] decide everything.
Children can still behave differently.
Let's send one [music] message.
The message says, "Move."
The parent defines [music] the idea of moving.
But each child decides how to move.
Think about vehicles again.
A car, a bike, a bus.
You give the same instruction, "Move."
The car drives.
The bike pedals.
The bus moves smoothly [music] with many passengers.
Same message, different behavior.
Now imagine controlling each object separately.
Different instructions, different rules, different commands. [music] That would be complicated.
Polymorphism keeps things simple.
You send one message >> [music] >> and let objects handle the details.
This leads to something powerful.
You can talk to different objects in the same way.
You send the same message [music] and each one responds correctly.
You don't change how you give the instruction.
The object knows what to do.
So, remember this.
Polymorphism means one message, different behavior.
The sender doesn't need to care how each object responds.
>> [clears throat] >> Quick check.
When the same message [music] is sent, do all objects behave the same way?
No, they respond differently.
But, the message stays the same.
That's polymorphism.
Inheritance gives us shared behavior.
Encapsulation [music] protects it.
Polymorphism makes it flexible.
Together, they make systems easy to grow.
Now that objects can behave differently, how do we design them cleanly from the start?
That's where abstraction [music] comes in.
>> [music] >> Okay.
The next topic is I think polymorphism now clear to you what is polymorphism. So, the basic The basic you can say functionality is basically the function overloading. So, a function having we can create a multiple function and having the same name.
Okay. And the compiler will inside use a concept called name mangling. So, through name mangling it will understand what actually the function will do. The function overloading means function having same name.
Function having same name and have a different parameter, okay?
So, based based on the parameters, it will understand that what which function will be called, okay?
So, like if we add a two numbers, so there is a two parameter add three numbers give a three parameter function having the name add.
But, based on the number of parameters we will understand that which function will be called. In our example, if you see uh we have the line number 320 two function having same return type that is void with the name print. But, if you see the first function line number 320 having int as a uh int argument and in the 321 we have a double, okay?
So, based the user call if you if the user sending if you see the line number 324 the value 10, so the integer one will be called.
And in 325 10.5 that is a double value will be call a double version of that print, okay? So, in this way they perform the function overloading. The function overloading simple definition is a function same name but uh different parameters.
The number of parameters may be differ or the type of parameters may be differ.
Okay?
Next is binary operator overloading. So, you know that the binary operators are those operator that are working on a two operands.
So, the addition is one of that.
So, addition is one of that. Okay? So, if you see, we are performing a class point we are taking here where we have a two variable X and Y and the constructor is also a point taking a two variable int X1 and X into Y1 and in this way, we are assigning the value.
This is the short way to assign the value to initialize the member your member variables via constructor.
Okay? And here they perform the overloading of plus operator. Okay?
So, what a specialty is there?
Similarly, we have a unary operator.
Uh those operator involves only one operand.
And like negative negative uh uh and plus plus, they are basically the unary operators.
We have some special operators as well like uh square bracket, double star. So, they are the special operators.
And the the necessary condition is they must be non-static in nature. Okay?
Similarly, we can overload the stream of stream insertion and extraction also.
Okay?
So, all almost all the operators you can overload. Even you can overload new and delete also.
But, there are some exceptions also that cannot be overloaded. So, you have to remember that exception also. Scope resolution operator can't be overloaded.
Ternary operator can't be overloaded.
Member access operator can't be overloaded.
Pointer to member operator can't be overloaded. Even type ID is also not overloaded. So, please do remember these points. These are very important.
Because you can give the definition easily. Like the question maybe what is function overloading and which kind of operators can't be overloaded.
So, this kind of question maybe in examination.
So, next important one is inheritance.
I mention here two slides. One is for uh inheritance through the channel and other is also. So, the second one you can see for your practice and the first one is for the understanding only. So, I hope that you will understand it.
At the end, I will tell you uh Only 29 rupees. Six-day abacus summer camp now enrolling. We have top speed tricks for class 1 to 10. It's very useful for your child. Only 6 days double calculation speed.
Imagine doing the same work again and again and again.
Every time you build something new, you copy the same behavior, paste it again, fix it again.
That's not just tiring.
That's risky.
Programming found a better way.
>> [music] >> In Codeville, you'll notice something interesting.
Many objects [music] look different.
They have different shapes, different roles.
But deep down, they share a lot in common.
They move.
They react. They follow rules.
The similarities matter.
Without inheritance, every object must define everything itself.
The same movement logic.
The same reactions. The same rules.
Fixing one mistake means fixing it [music] everywhere.
That's how bugs spread.
That's how programs become fragile.
>> [music] >> Instead of repeating ourselves, we create a parent.
The parent defines shared behavior.
Things everyone should know.
Things everyone should do.
The parent becomes a single source of truth.
Change it once, and everyone benefits.
Think about vehicles. Cars, [music] bikes, buses.
They look different. They used differently.
But they share common behavior.
They can move.
They can stop.
They follow basic rules.
So instead of repeating that, >> [music] >> we define it once in a parent called vehicle.
Now think about employees.
A manager. [music] An engineer.
An intern.
They do different jobs.
But they share core behavior.
They work.
They follow company rules.
They contribute [music] to a team.
So instead of redefining that, we define [music] it once in a parent called employee.
Children [music] don't start from nothing.
They inherit from the parent.
They automatically receive shared abilities [music] without copying them.
Inheritance is not duplication.
It's connection.
Inheritance [music] doesn't make everything the same.
Think about vehicles again.
A car, a bike, a bus.
They all inherit how to move.
They all know how to stop.
But a bus can carry many people.
A bike moves differently.
A car balances speed [music] and comfort.
They reuse what's common and specialize what's different.
Inheritance doesn't make everything the same.
Children can add new abilities or change how something behaves. [music] They reuse what's common and specialize what's different.
That balance [music] is powerful.
So, remember this.
Inheritance lets you reuse behavior without rewriting it.
The parent defines what's shared.
The child [music] defines what's special.
When a child gets behavior from a parent, is that behavior copied or shared through inheritance? [music] It's shared, not copied.
One definition used by many.
That's inheritance.
But here's something even more interesting.
Different children can respond differently to the same action.
That idea [music] is called polymorphism.
So, uh inheritance is basically you know the concept. So, good question what is inheritance? So, inheritance is a mechanism through which the parent will share the properties and behavior to the child class, that is called the derived class. So, it follows is a relationship. Please be remember, it follows the is a relationship.
And if there is a has a relationship, that is called a composition. So, in C++ we generally follow the is a is a relationship. Important question is what is inheritance and the type of inheritance, okay? And the you have to write a basic syntax also.
So, inheritance is basically uh from moving from generation to specialization or the parent class will share the property and behavior to the derived class. So, we have uh multilevel inheritance, multiple inheritance, hierarchical inheritance, and you can say hybrid inheritance. So, as I mentioned here, we have So, you have to remember we have a single inheritance that is hierarchical as well. How we write a inheritance? If you see, we have a class the base class that is animal here, and we have a derived class a dog is there. So, the this is the base class having a one function that is eat. So, you know that any every animal is eat something.
So, here we take a dog which is a derived class.
And and this is a syntax to inherit the single inheritance, okay?
So, similarly we can derive a class two. We have a class cat that is inherited from the animal.
Okay. So, if you if you draw it if you draw it, so animal at the top then dog and then cat. So, it will it will make a structure and he make a object of dog my dog and my dog dog it will inherited from animal and this function will be called. Similarly my dog dog bark is receiving the bark is function inside the dog. So, if you see inside the dog class there's a copy of this function as well which is public in nature from the animal. So, dog having a two function.
Okay?
Similarly for the cat.
So, you have to remember the syntax as well. Okay?
So, initializing a base class data.
So, you can initialize the base class data.
Okay? And second thing is whenever the constructor is called because you are creating the object of your derived class. So, the object will be called from top down. First the base constructor will be called then derived constructor will be called. Please be remember the constructor will be called in top down manner while the destructor will be called from bottom up. Okay?
Yes, code will be there.
Without code there is no programming.
So, that's why when I complete the inheritance we the inheritance is a single inheritance. I mentioned there how we inherit. Okay? Similarly if you see we have here we have a class base and that base class is derived also.
This is a derived class. You have to remember the syntax how we perform the inheritance. Okay? Similarly how we perform a multiple inheritance.
So, like here we have a class YouTuber.
Okay? We have a class engineer and a person like me is basically uh with you a YouTube channel that is a YouTuber and also engineer in nature.
So, both the properties are getting by me. So, it is called the multiple inheritance. And some if someone who is is the part of uh our education system and don't know about me. What if they go through our channel, they said that I'm a YouTuber, okay? And someone someone who knows me from the my education academics, so they will tell me tell you that the person is a engineer.
So, if you see there is ambiguity, okay? So, whenever we do uh multiple inheritance, there's a problem of ambiguity, okay? Because uh And this ambiguity will create sometimes a problem that is called a diamond problem. So, this is a diamond problem. We are going to discuss diamond problem now because this is this one is very important question.
So, that's why for for for this problem only the Java remove the concept of multiple inheritance, okay?
Java support only multi-level inheritance. So, I'm going to run this channel. This is one of the important concept and you must know for the tomorrow examination.
So, I'm going to run this.
And if you any doubt in this, please let me know.
I saw your chat always. If you're getting any any problem and if you're not able to understand Introducing Paper like you've never seen before. Your all-in-one writing essential.
Recycling is great for both Hello friends. Welcome to another C++ interview question and the question is what is diamond problem in C++?
And this question is generally asked for freshers interview, okay? So, what do you mean by diamond problem here? So, if you see the class hierarchy here, I'm inheriting this A into this B and C both. A is coming into B and C and these two B and C are inherited into this D.
So, it is actually looking like this. A is coming to B and C and both B and C are coming to D. So, this is looking like a diamond, okay? That's why this is called diamond problem. And what is the problem in this?
The problem is this A is coming two time in this D. If you inherit something, then except that constructor and destructor, things come from here to here. Okay? And two times A will be there. And you are again inheriting B and C into D. That's why the copy of A will be two time in this D. Okay? So, here is some example I have given. The A object will have its only A memory. But B, as B is inheriting A also, then B will have this B integer type and A will also be there in that. Okay? So, if you will print the size of B, it will print 4 + 4 8 bytes.
Okay? So, if you see B's object memory layout will be A and and C, C will be again A will be there in C and the C part will be there in that C again.
Okay? And what will happen in D? As you are inheriting B and C both, then the both will come here. So, what is this? A and B. So, this A and B will come and A and C will come. Okay? And this is the D part of that class. Okay? So, if you see here, there are two A in this. Okay? So, there comes the ambiguity problem. If you will try to access this A, which A should be accessed? Either this A or this A. And this is called diamond problem. Okay? So, this diamond problem doesn't comes until unless you just touch that A. I mean, the ambiguity variable. Okay? So, we'll see that. If you create this and you will compile it, it won't create any problem. Now, if you will use it, then only it will create the problem. So, I will assign something to that. Now, we'll compile that and it will say error request for member D A, which is ambiguous. Okay? So, this is statement is creating problem. This is statement.
Okay? Not this is If you are not accessing this A, which is coming from A, which is causing the problem here, I mean the ambiguity problem, if you are using this D, then it is okay. So, I can just show you that.
In case of B, it's okay. In case of In case of B, it's okay. In case of C, it's okay. Okay? If I will do it like this, and I will compile, it will successfully compile. So, there is no problem in accessing B, C, and D because B is unique, C is unique, and D is also unique. The only problem is A, okay? A is two times, that's why if we are accessing A here like this, it is creating problem, okay? If this is A, we will compile, it will say the error, okay? So, how to solve this problem?
The solution to this is you need to inherit this A virtually. So, what is the syntax of that?
Okay, this is the syntax to inherit class virtually.
You will write this virtual in this case. And now if you will compile, it will compile successfully. So, let's go ahead and check that.
See, it compiled successfully, and you're using A. Now, try to understand what is happening here after writing this virtual in this case, okay?
So, when if you are writing virtual in inheritance case, and when the compiler will go and create the memory layout for this D, it won't create this A two time.
Okay? Because it knows that you are inheriting it virtually, so the A will come into D virtually, okay? Virtually means it won't be two time, it will be one time only, okay? It will be separately there for B and C, okay? So, there won't be any changes here. It will be A only, and this is also going to be A. But here, it will remove either this A or this A.
So, that is the way to solve this problem, okay? So, that's it. This is So, you understand that basically what is a diamond problem and we use a virtual keyword in order to resolve it. Okay? So, this is one of the very important topic that will be generally asked in examination also.
So, the next important topic is your polymorphism. We already did virtual function. We did in We have a dynamic binding. Okay? There are two type of binding. One is static, other is called a dynamic binding. So, dynamic binding also also called run-time polymorphism or run-time binding. So, basically uh We use virtual keyword in that case because the reason behind it for run-time we run-time means when the code is executed at that time we decided which kind of which function will be called. Okay? You know when the compilation is performed so the function will be bind at that time. But that is for run-time. Okay? Uh static binding.
So, at the start if the if the if the if there is no polymorphism. For example, you are just you are playing video game. Okay? So, once you start your game uh then you then you decide that two person will be play the game or a three people three person or a single person will play the game. So right?
Game is already in a running stage. So dynamically it is to be performed. Okay?
So, that is called run-time polymorphism.
So, generally we perform using a pure virtual function. So, the pure virtual function is basically uh like the syntax is in line number 581. You can use a keyword virtual then the function name void draw here and equal to zero. If you write like this it is called a pure virtual function. Or similarly, we are writing a virtual destructor also.
virtual then till sign then shape okay.
If all you know the next important topic is object slicing.
So we You know every everything about the inheritance like generally what happen if that B is inherited from classes and only we write them we create an object of class B okay. The most recent one.
Generally traditionally in programming we do this but what happen actually if if we make an object of class A okay of a base class equals to new drive class.
Okay.
class base class name is equal to new drive class okay. So what happen actually?
Although you are you are equaling the uh you're equate equal to the drive class of drive class but the issue is the your function is already having a knowledge about the A because at the right hand side you are taking your base class object. You are getting the base class object is equal to new drive class okay with the bracket.
So what happen in that case there's a concept that is called object slicing.
Slicing means you are you cut the mango the piece of mango that is called a slice. Similar manner A having only knowledge about its area. So it will it will not allocate the complete memory as it is required by your drive class also.
It will get a memory only for that A section only.
So that is called object slicing. So I want that you understand it that's why I'm running this video.
And it will help you in that tomorrow's examination, also.
I'm currently working as a senior manager. Hello, friends. Welcome to another interesting C++ interview question. And this question is, what is object slicing in C++? Okay, so we'll see that what is object slicing.
Here we are creating derived object d o b j and base object and we are assigning the derived object into base object.
That's the simple code, okay? And what is this derived object? It is having base object, I mean, it is inheriting base object. So, here is the code. So, if you see, you're copying this derived object into base object. Okay? So, what exactly this base object would have the memory for? This base object will have memory for only this base variable here.
It is only having memory for base variable, but derived is having memory for both, okay? For base variable as well as derived variable here. Okay? So, if you are copying derived object, which is this one, which is having both variable inside, so it is having both variable memory into base object, which is just simply one variable, so in that case, only base variable information is being copied from this one to this one. And the derived information, which is this d variable, will not be copied here, okay?
So, that's the only thing which comes under slicing, I mean, the object slicing in C++. So, that is what is called object slicing in C.
I think object slicing is clear from that part. video. The base the base class object will get assigned to a uh derived class object and not a complete memory is allocated. So, that is a slice, okay?
So, the next concept is basically your file handling. These are the notes of file handling. Please go through it.
Okay. Next concept is template. Uh they're very important concept. We have a now two very important concept. One is file handling that I mentioned in my slide that I shared with you. So, you can go through it.
Other concept is template and the last concept is your uh STL. Okay?
So, what are template? Templates are basically a generic programming. They allow us to write a code in a general manner and based on the user input that template will works, okay?
So, our function template is a blueprint for the function. Instead of typing the specific data type, we just uh type some kind of uh keyword like T for the type and based on user input that type will be changed. So, suppose you are making a program for addition of a number, but that number can add your float value also, double value also, integer value also because it will be a general one. So, this is a simple code to understand this one. Here we create one template type name T if you see at the line number 636.
It is used to find the maximum of two two. We don't know that two what are that two basically. The return type is T find max TA TB. So, data type is not mentioned here, okay? We just mention type name T and that value will be taken at a run time. So, if you see inside the int main, we find the max find max int if you Uh, in the scriptlet we are writing the int. So, 5 and 20 will go. So, by default this function will change its behavior. The T will be replaced by int and it will perform the uh, greater than two number by with respect to integer. Similarly, for the double as well.
So, this is called the template. The template means a generic kind of programming and its behavior will change when the we enter the value. Okay, based on that it will it will decide its data type.
Okay. So, if you remember something something there is in Python as well.
Okay.
So, just like a function template we also able to create a class template as well. If you see we we created here a class template. The keyword is same at the line number 665 template type name T. Then class box. If you see private T content. So, there is uh, there is no data type with the content.
Similarly, if you see one function is there that is box and that is constructor as well. And T value is a parameter. So, that that value based on the when the object is created the value will be assigned. It will change like in our case in the line number 679 we are sending some integer value 123. In the line number 683 we are sending some value string inside this and it will change its behavior. So, it is a generic kind of programming. So, uh, in industry some person is asking what to do in the large code in the industry as well. So, generally we are using Visual Studio.NET there in industry. And this is the environment where I am uh, explaining you these these codes. So, it is a Visual Studio.NET and if if you are interested to learn this, come to my cabin. I will definitely tell you how we work in industry on the large scale projects like this.
So, there is advantages of template that is an important question.
You write the logic once and it work for the compatible compatible data type.
Uh, one thing is there that is called a code code bloat. It is a disadvantage kind of thing. The compiler generate a new copy of the template for every data type, so it will If we have a 10 different data type, it will compile for a 10 different distinct version of that kind, and it will increase the size and executable size also. That is called the code bloating. Code bloating is an important topic for the interview point of view, not for the your examination, but it is important to do this one important.
Uh, similarly, we have a type safety.
The last topic is the STL.
That equals standard template library.
So, in the inside the standard template library, there are three important component. One is called the container, other is iterator, and third is algorithm.
So, container will contain the data.
Algorithm, what operation you want to perform? Like you want to sort out the numbers, so sort is one of the uh, algorithm there.
And iterator is how it is it is for the traversal on data. The data of the whatever the data is inside your container, so it will be iterated through iterated. So, one by one we are going to discuss this one.
So, if the question is from the STL, the most generally most probably the question is what is STL and explain it, and it is one of the good question for the examination.
So, major component of the STL is container. Container store the original data, organize it, and inside vector, list, deque, set, multiset, map, multimap, hash {underscore} set, hash {underscore} map. So, these are the containers.
Container means that contains the data, okay?
So, generally, we are using vector.
Basically, in competitive coding, we are generally using vector or a list, Map is also there, but map having their own features.
Algorithm, what kind of operations we can perform on that data? That is reverse, find, sort, count, copy. There are many operations are there that we can perform using the algorithm part of the STL.
And iterator is how we traverse, okay?
Iterator acts like a generalized pointer and forms the bridge between the algorithm and container because container contains the data and what operation what algorithm do we apply our data that is through iterator only cuz iterator will move from one point to another point.
So, iterator allow algorithm to remain container independent, okay?
So, we have a simple I believe example of that. We create one vector here having three values 7, 10, and 17.
And if you see we want to reverse it, so std::reverse, v.begin, v.end.
And we have a for loop, int x : v and it will display all the values in the reverse order. So, if you see it itself reverse from beginning to end.
We just give the beginning and end and the iterator algorithm will itself works. We are not writing any code to reverse it. So, itself it is there algorithm is available. You just have to uh like ready to eat is there, no? It is ready to work. You have to just call it.
Please put the data and it will do the task. So, it is a beauty of STL and STL generally we use in competitive coding.
So, we need uh good practice here. So, we have a container, algorithm, and iterators.
These two things are there. So, STL is very important section uh for the competitive point of view.
Okay? And also tomorrow examination, yes. It is very important.
So, you have to remember this one. Last topic for the session is I will share the slides. It has a enough videos, enough uh important questions. If you go through this, uh you can definitely score good tomorrow. Don't worry about that.
So, this is very important PDF on file handling and I want to share with you.
And now I'm going to discuss also of the basic about this PDF.
So, I also give thanks to Siddhartha for making this uh file handling and I love it because it is a way I am teaching the students file handling.
Uh generally, what is file? File means the collection of some data, okay?
And we are using file handling to store the data into our secondary storage.
So, what generally happen? We explain so well that generally what happen when we need any data, okay? So, that data will be in basically random access memory or read-only memory. What happen? Once the electricity switch off, okay? That data is gone because the main memory is volatile in nature. So, you need something that will store the data permanently.
Okay? So, in that case, the file handling concept helps us.
So, we have something that is called inputs and outputs stream in that case.
These are the file stream classes. If the big question is there, you have to make this diagram.
A stream is nothing but a flow of data.
In the object-oriented programming, the stream are controlled using the class, okay?
Suresh is giving such a fantastic uh this concept in this uh PDF. I love it.
I go through it in the morning and uh I appreciate his working work.
So, you have to make such a diagram and for if the file handling theory question is there.
So, we have two kind of stream here.
It's called input stream that is ice cream classes control input and output function in the case of a file.
The [snorts] function get, get line, read overloaded extraction operator and defined in the ice cream classes while the function put, write overload insertion. If you see, they they are related.
Get the data, get line, read input extraction operator. They are inside the ice cream class. While out out stream contain put, write, and overload insertion operators.
So, these are basic details of file buffer for buffer. Buffer is a small area. Sets the file buffer to read and write. It holds constant open for used in the function open and close as a member.
If stream, off stream, read So, they are the classes you must know about it.
Steps to file operation. So, if you have perform any file operations, you need to specify the file name.
Opening the file in desired mode. We We just go through what is the desired mode.
Reading or writing the file. Detecting error if there is, and then if there is no error then closing the file. So, in order to perform operation like file opening, the first operation is open the file.
Create the file of a stream object and connecting it with the file's name. The class if stream, off stream, and if stream can be used for the creating the file.
They are called as by one is constructor of the class and member function open.
So, we have like off stream out text, if stream in list. When the object are created, a constructor is automatically executed and objects are initialized. We know already from our last few minutes lecture. In the same way the file stream object is created created using a suitable class and it is initialized with the file name. The constructor itself use the file name as the argument and opens the file. The class ofstream creates output stream object and class ifstream creates input stream object. So, these are the way we are creating it. Okay?
So, you have a program. If you see this diagram, you have a program.
You have a output stream and output stream will output the data on a file on a disk. In between this this row is basically your RAM. Okay? And this is the program you're writing. Your variable are there. Some data is there.
And you store this using outstream, you store this data into this file. Okay?
Similarly, input stream, you are taking data from file into your program. So, please be remember how it works.
So, if you see this is simple code, you have ofstream one file that is text. You enter name and see out enter name and then see name will take see out enter age see name and if you see here we have two out. These two out basically what they perform, whatever the input you are taking here, these two out will be transferred to your uh file.
Okay?
The text the file name is text. In this text t e x t, the name and age will be stored.
Okay?
These are taken from the user from the console and this will be stored in a file. And then at the end the file will be closed. This is simple program to take an input from the user and store it into a file.
So, we open the file with the name text.
We take a name from the user as an input in a variable name. So, these these are now in RAM. You can say these are now in RAM.
Okay? And once I perform this out operation, So, data that we get from the that data place in the RAM will be moved to your text file, okay? So, that will be permanent store now, okay? If the now the light is gone, the data will be present for us. So, volatility is removed in this manner.
So, you this is a basic of file handling. This file is too lengthy, but you you at least know how the file will be open or the file will be closed. And there are different opening mode like file can be opened in uh you can say append mode.
Okay, we saw that there is a mode open mode.
Okay, edit mode at the end of the file, at the start. So, there there there is a inbuilt function for that, okay? Uh similarly, we can check the errors.
So, I hope this will be clear to you.
Okay?
And I almost complete all the points uh that are required that are in your syllabus and required for tomorrow exam.
So, I hope that you will prepare to well.
Okay?
And all the data will be shared with you. I think uh I also share my all the data at the end of the lecture and I also tell you uh a little idea about the market. Although I don't have a knowledge about it, but I will also do some kind of guesswork for that, okay? So, because I can't interfere with any of those job, okay?
My work is to teach you people and I'm doing my job.
So, still if you have any kind of uh doubt, so please let me know.
I will explain you.
And I'm happy that you people attend this lecture today, okay?
Although this is also my first experience, but I believe that as much as we can do best for you.
I did.
And I will send my these notes also so that if anybody wants to learn again and want to revise it, then you people may revise. Okay?
So, I'm going to stop this recording this session.
Thank you. Thanks a lot.
Ähnliche Videos
Agentforce NOW AMA: Build with React and Salesforce Multi-Framework
SalesforceDevs
490 views•2026-05-28
How agent o11y differs from traditional o11y — Phil Hetzel, Braintrust
aiDotEngineer
450 views•2026-05-28
Re: 🗣️📍theprophedu📍2026 GST 103 CLASS (E-EXAM REVISION)
theprophedu
636 views•2026-06-04
WEB TECHNOLOGIES UNIT-2 | Degree 4th sem BCOM Computers web technologies unit-2 full explanation💯✅
LearnwithSahera
1K views•2026-05-29
More tests are always better? How to use AI to identify tests that bring little value
Alliance4Qualification
335 views•2026-05-29
Search Algorithms Explained in 60 Seconds! 🤖💨
samarthtuliofficial
218 views•2026-06-01
People of Game of Thrones using JavaScript DOM
AltCampus
296 views•2026-05-30
Instagram accounts got PWNed
EricParker
13K views•2026-06-03











