- Type
- Quiz
- Course
- CS201 Introduction to Programming
- Size
- PDF 334 KB
- Updated
- 23 Oct 2026
You get 3 free files a day on the website. Add the Chrome extensionSign in with the extension for 30 a day.
Preview text
Text from pages 1, 2, 3 of 7. Download the file for all 7 pages.
CS201 Notes for Final Term (Lecture#31-38) preparation
Operator Overloading is quite similar to Function Overloading.
There are two types of operators to overload: unary and binary.
Unary operators are the ones that require only one operator to work. Unary operators are applied to the left of the operand. For example, ^, &, ~ and!.
Binary operators require two operands on both sides of the operator. +, -, *, /, %, =, < and > are examples of binary operators.
A unary operator takes only one operand & one argument (++,--), while binary operator takes two operators & two arguments.
C++ built-in operators work for built-in (primitive) data types but for user defined data types, user has to write his/her own operators.
There are some restrictions while performing Operator Overloading. For example, only existing C++ operators are overloaded without creating a new one in the language.
Also, it should not impact the type, semantics (behavior), arity (number of operands required), precedence( high/low precedence) and associativity (left/right) of the operator.
For binary member operators,operands on the left drives (calls) the operation. Operator functions written as non-members but friends of the class, get both the operands as their arguments.
Operators can be written as non-members and even without making them friends. But this is tedious and less efficient way, therefore, it is not recommended. Both C and C++ have a set of rules for converting one type to another. These rules are used in the following situations:
❖ When assigning a value. For example, if you assign an integer to a variable of type long, the compiler converts the integer to a long.
❖ When performing an arithmetic operation. For example, if you add an integer and a floating-point value, the compiler converts the integer to a float before it performs the addition.
❖ When passing an argument to a function; for example, if you pass an integer to a function that expects a long.
❖ When returning a value from a function; for example, if you return a float from a function that has double as its return type. In all of these situations, the compiler performs the conversion implicitly. The conversion explicit is possible by using a cast expression.
Can we do conversion with objects of our own classes?
The answer is yes. If we go to the basic definition of a class it is nothing but a user defined data type. As class is a user defined data type, we can also define conversion on it.
Array of Object: A class is a user-defined data type. Objects are instances of classes the way int variables are instances of ints. The declaration of arrays of user-defined data types is identical to the array of primitive data types. New is called before the constructor, and that delete is called after the destructor.
A global array called pool that can store all the Name objects expected.
Copying a File in the Reverse Order means the last byte of the input file will be the first byte of the output file, second last byte of the input file will be the second byte of the output file until the first byte of the input file becomes the last byte of the output file. ❖ The default constructor is defined by the C++ compiler automatically for every class that has no default constructor (parameterless constructor) defined already. ❖ The default constructor (parameterless constructor) is called for each element in the array allocated with new.
❖ The new operator returns a void *, accepts a parameter of type size_t. ❖ The delete operator returns nothing (void) and accepts a pointer of void * to the memory block.
❖ With new operator function, a block of memory is allocated first and then constructor is called. (Difference b/w new & delete operator)
❖ With delete operator, destructor of the object is called first and then memory block is deallocated.
❖ By overloading new and delete operators, only allocation and deallocation part can be overridden.
❖ The same pointer that is returned by the new operator, is passed as an argument to the delete operator. These rules apply to both, if operators (new and delete) are overloaded as member or non-member operators (as global operators).
❖ By overloading the array operator ( [] ), one can implement mechanism to check for array bound.
A C++ stream is a flow of data into or out of a program, such as the data written to cout or read from cin. cin is an example of an istream. ostream is a general purpose output stream. Streams are nothing but an ordered sequence of bytes. They allow data to move from one part of the computer to another which may be the screen or key board from and to, or from memory or files on disc and so on. Byte stream is used to connect the source and the destination.
“Every stream has an associated source and a destination”
Related CS201 files
All CS201 files →- CS201 Midterm Highlighted Handouts by VU Topper RM Highlighted PDF 2.1 MB
- CS201 Final Term Quiz 3 July 2023 Part 3 by Miss Mehwish Final term PDF 665 KB
- CS201 Short Notes Best Way to Pass Quiz PDF 120 KB
- CS201 Quiz 1 Fall 2022 by Muhammad Zaman Quiz PDF 1 MB
- CS201 Quiz 2 Set 2 Quiz PDF 3.5 MB
- CS201 Quiz 1 Updated May 2023 by Attiq Kundi Quiz PDF 3.3 MB
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.