LOCAL(45); } Q6. What is the difference between Object Oriented Programming and Procedural Programming? Ans : Object Oriented Programming Procedural Programming Emphasis on Data Emphasis on doing things (functions) Follows Bottom-Up approach Follows Top-down approach in program design in program design Data hiding feature prevents Presence of Global variables accidental change in data increase chances of accidental change in data Features like data encapsulation, Such features are not available polymorphism, inheritance are present Q7. Differentiate between a Call by Value and Call by Reference, giving suitable examples of each? Ans: Call by Value Call by Reference The called function creates its own The called function accesses and works copies of the original values sent to with the original values using their it. references. Any changes that are made in the Any changes that occur in the function function run, changes in the run, changes in the original values are original values are not reflected. reflected. void change(int b) void change(int &b) { { b = 10; b = 10; } } void main() void main() { { int a = 5; int a = 5; cout<<”\n a = cout<<”\n a = change(a); change(a); “<<a; “<<a; cout<<”\n a = cout<<”\n a = “<<a; “<<a; } } Output will be: a = Output will be: a = 5 5 a = a = 5 10 Q8. What is a parameter? Differentiate between an actual and a formal parameter with an example? Ans : Parameter is the variable / value passed to a function or the variable that is used as the incoming values in a function. The variables / values passed to a function are called actual parameters. The variables that are used as the incoming values in a function are called formal parameters. For Example: void change(int b) // b is the formal parameter { b = 10; } void main() { int a = 5; change(a); // a is the actual parameter cout<<”\n a = “<<a; }
LOCAL(45); } Q6. What is the difference between Object Oriented Programming and Procedural Programming? Ans : Object Oriented Programming Procedural Programming Emphasis on Data Follows Bottom-Up approach in program design Data hiding feature prevents accidental change in data Features like data encapsulation, polymorphism, inheritance are present Emphasis on doing things (functions) Follows Top-down approach in program design Presence of Global variables increase chances of accidental change in data Such features are not available Q7. Differentiate between a Call by Value and Call by Reference, giving suitable examples of each? Ans: Call by Value Call by Reference The called function creates its own copies of the original values sent to it. Any changes that are made in the function run, changes in the original values are not reflected. The called function accesses and works with the original values using their references. Any changes that occur in the function run, changes in the original values are reflected. void change(int b) { b = 10; } void main() { int a = 5; cout<<”\n a = “<<a; change(a); cout<<”\n a = “<<a; } Output will be: a = 5 a = 5 void change(int &b) { b = 10; } void main() { int a = 5; cout<<”\n a = “<<a; change(a); cout<<”\n a = “<<a; } Output will be: a = 5 a = 10 Q8. What is a parameter? Differentiate between an actual and a formal parameter with an example? Ans : Parameter is the variable / value passed to a function or the variable that is used as the incoming values in a function. The variables / values passed to a function are called actual parameters. The variables that are used as the incoming values in a function are called formal parameters. For Example: void change(int b) // b is the formal parameter { b = 10; } void main() { int a = 5; change(a); // a is the actual parameter cout<<”\n a = “<<a; }