Order PDF of any content from our website with a little minor Fee to donate for hard work. Online MCQs are fully free but PDF books are paid. For details: contact whatsapp +923028700085 Important notes based PDF Books are available in very little price, starting from 500/-PKR; Order Now: contact whatsapp +923028700085

VU Past Paper CS201 – Important Subjective Questions & Answers

1. What are the main types of operators in terms of number of arguments?

Operators are classified based on the number of operands they require.

  1. Unary Operator
    • Takes one operand
    • Example: ++a, --a
  2. Binary Operator
    • Takes two operands
    • Example: a + b, a * b
  3. Ternary Operator
    • Takes three operands
    • Example: condition ? value1 : value2

2. What is the β€œthis” pointer?

The this pointer is a special pointer available inside member functions that points to the current object of the class.

Example

class Test{
int x;
public:
void setX(int x){
this->x = x;
}
};

3. What are manipulators?

Manipulators are special functions used with input/output streams to format data.

Example

endl
setw()
setprecision()

Example:

cout << setw(10) << 100;

4. If requested memory is not available what do malloc/calloc/new return?

  • malloc / calloc β†’ return NULL
  • new β†’ throws bad_alloc exception (or returns NULL in older compilers)

5. What is memory leak?

A memory leak occurs when dynamically allocated memory is not released using delete or free, causing memory wastage.

Example:

int *p = new int;

If delete p; is not used β†’ memory leak occurs.


6. What does code optimization mean?

Code optimization means improving program efficiency without changing output.

Goals:

  • Reduce execution time
  • Reduce memory usage
  • Improve performance

7. Difference between structure and class

StructureClass
Members are public by defaultMembers are private by default
Mostly used for simple dataUsed for full OOP programming

8. Difference between endl and \n

endl\n
Inserts new line and flushes bufferOnly inserts new line
SlowerFaster

Example:

cout << "Hello" << endl;
cout << "Hello\n";

9. When does an object get destroyed?

An object is destroyed when:

  • It goes out of scope
  • Program ends
  • delete is called for dynamic object

At that time destructor is executed.


10. What is static variable and its lifetime?

A static variable is initialized only once and retains its value between function calls.

Lifetime = entire program execution

Example

void func(){
static int x = 0;
x++;
}

11. Output of the following functions

Function 1

void func1(){
int x = 0;
x++;
cout << x << endl;
}

Output if called 3 times

1
1
1

Because x is created again every time.


Function 2

void func2(){
static int x = 0;
x++;
cout << x << endl;
}

Output

1
2
3

Because static variable retains value.


12. What is friendship in classes?

A friend function can access private and protected members of a class.

Example

class A{
private:
int x;
friend void show(A);
};

13. Limitations of friendship

  1. Friendship is not inherited
  2. Friendship is not mutual
  3. Friendship is not transitive

14. What are disadvantages of templates?

  1. Code becomes difficult to read
  2. Compiler errors become complex
  3. Debugging becomes harder

15. What is assignment operator?

The assignment operator (=) is used to assign the value of one object to another.

Example

a = b;

16. Constructor and Destructor call order

If object of class A is inside class B

class B{
A obj;
};

Constructor order

  1. A constructor
  2. B constructor

Destructor order

  1. B destructor
  2. A destructor

17. Unary vs Binary operator

Unary OperatorBinary Operator
Works on one operandWorks on two operands
Example: ++aExample: a + b

Overloading Syntax

return_type operator symbol(parameters);

Example

Vector operator+(Vector v);

18. What are steps to design a good program?

  1. Problem analysis
  2. Algorithm design
  3. Coding
  4. Testing
  5. Debugging
  6. Documentation

19. What is truth table?

A truth table shows the output of a logical expression for all possible combinations of inputs.

Example

ABA AND B
000
010
100
111

20. What is default constructor?

A constructor without parameters is called a default constructor.

Example

class A{
public:
A(){
cout<<"Default Constructor";
}
};

21. What is conversion constructor?

A constructor that converts one data type into class type.

Example

class Test{
int x;
public:
Test(int a){
x = a;
}
};

22. Why are utility functions kept private?

Utility functions are kept private so they:

  • cannot be accessed outside the class
  • are used only internally
  • improve security

23. What does free format language mean?

C and C++ are free format languages, meaning:

  • spaces
  • tabs
  • line breaks

do not affect program logic.


24. Types of user defined conversions

  1. Conversion Constructor
  2. Operator Conversion Function

25. What is STL?

STL = Standard Template Library

Provides ready-made:

  • containers (vector, list)
  • algorithms
  • iterators

Advantages:

  • Code reuse
  • Efficiency
  • Type safety
Contents Copyrights Reserved By T4Tutorials