Oct 29 2022 Flashcards
what is the syntax for return by address
Int * fun(int n) {
int *p=new int[n];
for(int i=0;i<n;i++)
p[i]=i+1;
return p;
}
what is the syntax for return by reference
Int & fun(int &a) {
cout«a;
return a; }
Explain Code
Int & fun(int &a) {
cout«a;
return a; }
Int main() {
int x=10; fun(x)=25; cout«x;
}
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
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
What are the main points regarding local variables vs global Variables
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
Where are the global variables stored
The code Section , created at loading time before the execution of the program
Where are local variables stored
The Stack
What is difference and similarity b/w between Static. and global variable
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
What is Modular Programming
Mostly just Functions that are relavent
How to avoid mishadling of data
Make data private show functions
What is Abstraction
How do we have POLYMORPHISM
Through Inheritance
data = ?
function = ?
property
behavior
- 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