- Type
- Final term past paper
- Course
- CS201 Introduction to Programming
- Size
- PDF 258 KB
- Updated
- 23 Oct 2026
You get 3 free files a day on the website. Add the Chrome extension for 30 a day.
Preview text
Text from pages 1, 2, 3 of 6. Download the file for all 6 pages.
CS201 Notes for Final Term (Lecture#39-45) Preparation
Pointers: Pointer is a special type of variable that contains a memory address. It is not a variable that contains a value, rather an address of the memory that is contained inside a pointer variable.
The & operator is used to get the address of a variable or an object. The & sign is also used as a short hand for a reference.
Reference: A reference can be considered as a special type of pointer as it also contains memory address.
Difference: Pointers may point to nothing while references always have to point to something. The references used when we are implementing the call by reference & we can implement the call by reference without using the * operator.
Call by Value: We call a function and pass an argument, an object or variable to the function. Original data remains at its place and a temporary copy of it is made and passed to the function. Whatever the function does with this copy, the original value, in the calling function, remains intact. This is a call by value.
Call by Reference: If we want a function to change something in the original object variable or whatever, then that variable or object by reference would be passed. To do this, we don’t make temporary copy of that object or variable. Rather, the address of the variable is sent. When the function manipulates it, the original object will be manipulated, effecting change in its values.
Which one is Efficient?
The use of call by reference is also important for the sake of efficiency. If we have a large object, sending of its copy will be something insufficient. It will occupy a large space on the stack. Here, we can use call by reference instead of call by value only for efficiency while we need not to change the original object. For this, we use a keyword const that means that a const (constant) reference is being passed. The function can use its values but cannot change it.
In static memory allocation, whenever we declare an array, we have to mention its size. It is necessary, as otherwise no memory will be allocated.
We do initialization as int i = 0 ; OR int i ; i = 0 ; The default assignment of C will carry out. ( If we have not defined the overloaded operator for Assignment). The default assignment is a member-to-member assignment.
A copy constructor is a special constructor for creating a new object as a copy of an existing object. Constructor that will create a new object with a full copy of the other object. This is also known as deep copy as opposed to shallow copy.
Rules for Using Dynamic Memory Allocation:
- First, we must define a constructor for it. Otherwise, we will not be able to carry out dynamic memory allocation.
- Secondly, we must write an assignment operator for that class. This assignment operator should first check the self-assignment and then make a deep copy.
- Thirdly, as we are doing dynamic memory allocation in the constructor, it is necessary to provide a destructor. This destructor should free the allocated memory. Matrix m2 = m1 ; It is not an assignment operator. It is a copy constructor.
A class is a user defined data type and it can be used inside other classes in the same way as native data types are used. Thus we can create classes that contain objects of other classes as data members. Construction of an object is that the contained data members of the object are constructed before the object itself. The order of the execution of initializes is the same as the order of declarations of objects inside the outer class. The default scope for members of structures is public whereas the default visibility for class members is private.
A class can contain instances of other classes as its data members.
- It is a way of reusing the code when we contain objects of our already written classes into a new class.
The order of destruction of an object is reverse to this construction order, where the outer object is destroyed first before the inner data members.
- Initializes list is used to initialize the inner objects at the construction time. Classes defined within other classes are called nested classes.
A template is a sketch to draw some shape or figure. Template is allowing us the reuse of a certain shape/code.
For normal code, you would use a class template when you want to create a class that is parameterized by a type, and a function template when you want to create a function that can operate on many different types.
Macro is a code substitution while #define is a value substitution.
Static variable members are used to define ordinary classes. The static variable has a single copy for the whole class. So there are not separate copies of the static data variable for each object like ordinary data members.
Advantages and Disadvantages of Templates:
Advantages: ❖ Templates are easier to write than writing several versions of your similar code for different types
❖ Templates can be easier to understand, since they can provide a straightforward way of abstracting type information.
Related CS201 files
All CS201 files →- CS201 Final Term Past Papers 2 with References Final term PDF 119 KB
- CS201 Final Term Past Papers 3 with References Final term PDF 364 KB
- CS201 Final Term Current Paper 2020 by VUBuddy Final term PDF 480 KB
- CS201 Final Term Past Papers 2024 by Qalb-e-Momin Final term PDF 10.7 MB
- CS201 Complete Handouts Set 2 Handout PDF 3 MB
- CS201 Current Solved Subjective Subjective PDF 224 KB
Get more out of VUBuddy, for free
- Unlimited downloads
- The explanation behind every MCQ answer
- Study offline on slow data
- 30 downloads a day instead of 3
- Sign in and buy Pro Semester here
One Pro Semester membership works in both the extension and the app.