Oct 29 2022 Flashcards

1
Q

what is the syntax for return by address

A

Int * fun(int n) {
int *p=new int[n];
for(int i=0;i<n;i++)
p[i]=i+1;
return p;
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
1
Q

what is the syntax for return by reference

A

Int & fun(int &a) {
cout«a;
return a; }

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Explain Code

Int & fun(int &a) {
cout«a;
return a; }
Int main() {
int x=10; fun(x)=25; cout«x;
}

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What does all of these mean

Return by Reference
* A function cal return reference
* It should not return reference of its local variables
* It can return formal parameters if they are reference

Once you understand these see what was the factor that made you understand this

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What does all of these mean

Return by Reference
* A function cal return reference
* It should not return reference of its local variables
* It can return formal parameters if they are reference

Once you understand these see what was the factor that made you understand this

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are the main points regarding local variables vs global Variables

A

Local Variable
1) Local Variables are only accessible in that function ( even main)
2) Once the function terminates the they are removed from memory

Vs

Global Variable
1) Accessible by all functions
2) They are in the memory as long as the program is running

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Where are the global variables stored

A

The code Section , created at loading time before the execution of the program

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Where are local variables stored

A

The Stack

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is difference and similarity b/w between Static. and global variable

A

Similarity
-> They are both there till the end of program
They are created in code section

Difference
-> Anybody function can access global variable , only function where the static variable was declared can access the static variable

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is Modular Programming

A

Mostly just Functions that are relavent

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How to avoid mishadling of data

A

Make data private show functions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is Abstraction

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How do we have POLYMORPHISM

A

Through Inheritance

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

data = ?
function = ?

A

property
behavior

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q
  • Many object can be created from same class
  • Object consumes memory equal to sum of sizes of all data members * Member functions don’t occupy memory
  • Member functions are called depending on object
  • . Dot operator is used for accessing members of object
  • Memory allocated for object is also called as instance

DO you understand these

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

If you want to access object property used name vs pointer write down the difference in syntax

A

r.length

p-> length ( Provided p stores the address of that object)

15
Q

Syntax for creating object in Stack using pointer
VS
Syntax for creating object in Heap using pointer

A

Rectangle r;
Rectangle *p;
p = &r

vs

Rectangle *q = new Rectangle

16
Q

What are the principles of Data Hiding

A

Data should be made private , function should be made public

17
Q

What are the type of constructors

A

Default C
Non Parameterized C
Parameterized C
Copy C

18
Q

What is the syntax of copy constructors and why

A

Test (Test &t){
a=t.a
p = new int[a]
}

The only thing is you are passing the object as reference , the name should be the same as class

19
Q

Possible error with copy constructors

A

If you are using pointer it might accidentally lead the same address of the array

20
Q

What are type of Functions a class can have

A
  • Constructors - called when object is created
  • Accessors / Getters - used for knowing the value of data members
  • Mutators /Setters - used for changing value of data member
  • Facilitator - actual functions of class
  • Enquiry - used for checking if an object satisfies some condition * Destructor - used for releasing resources used by object
21
Q

What is Scope Resolution Operators

A
22
Q

What is the rule for Inline functions , and why do we have to do this

A

Never write complicated functions inside the class, the machine code for the function is written with the machine code of main function

23
Q

Scope Resolution Operator and why do we need them in classes

A

So that the machine code of function and machine code of main function dont mix up

24
Q

What is syntax for Scope Resolution Operator for writing function which is not inline

A

Declare the function with within class

outside the class
int Rectangle::perimeter(){
}

25
Q

What is the difference between the struct in c and C++

A

C++ structs allows data plus function , C only data

26
Q

difference between class and struct

A

Everything by default in struct is public vs everything by default in class in private

27
Q

What is operator overloading

A

Conventional Operators can be added to classes that you make and mean something different

28
Q

What is the syntax for operator overloading

A

Complex operator+(Complex c)
{
Complex temp;
temp.real=real+c1.real;
temp.img=img+c1.img;
return temp;
}

29
Q

What is syntax of friend operator

A

class Complex
{
private:
int real;
int img;
public:
Complex(int r=0,int i=0)
{
real=r;
img=i;
}
void display()
{
}
cout«real«“+i”«img«endl;
friend Complex operator+(Complex c1,Complex c2);
};
Complex operator+(Complex c1,Complex c2)
{

Complex temp;
temp.real=c1.real+c2.real;
temp.img=c1.img+c2.img;
return temp;
}