Home | | Object Oriented Programming | Important Short Questions and Answers: Object Oriented Programming(OOP) - Overview

Chapter: Object Oriented Programming(OOP) : Overview

Important Short Questions and Answers: Object Oriented Programming(OOP) - Overview

Object Oriented Programming(OOP) - Overview - Important Short Questions and Answers: Object Oriented Programming(OOP) - Overview

 

1. Define object oriented programming?

 

OOP is an approach that provides a way of modularizing programs by creating partitioned memory areas for both data and functions that can be used as an templates for creating copies of such modules on demand.

 

2. List some features of OOP?

i. Emphasis is on data rather than procedures.

ii. Programs that are divided into what are known as objects.

iii. Follows bottom – up approach in program design.

 

iv.Functions that operate on the data of an object are tried together in the data structure.

 

3. What do you mean by nesting of member functions?

 

A member function can be called by using its name inside another member function of the same class. This is known as nesting of member functions.

 

4. What do you mean by friend function?

 

By declaring a non member function as friend of a class , we can give full rights to access its private data members (i.e.)A friend function although not a member function have full access rights to the private members

 

5.What are the special characteristics of a friend function?


to use an object name and dot membership operator with each member name

Usually it has the object as arguments.

6. What is a const member function?

 

If a member function does not alter any data in the class, then we may declare it as a const member function.

 

e.g. : void getbalance ( ) const; void mul(int,int) const;

 

7. What is a main function?

 

All the C++ programs start with the function main(). Function main returns the integer value that indicates whether the program executed successfully or not.

 

Syntax: main(){ }

8. What is the purpose for the return statement?

 

The return statement is used to return the value from a function. The statement return 0; returns the value 0. The return statement supplies a value from the called function to the calling function. 9. Explain function prototype?

 

It is used to describe the function interface to the compiler by giving details such as type number and type arguments and the type of return values. Function prototype is a declaration statement in the calling program.

Syntex: Type function_name (arguments); 10 Define macro?

 

A short piece of text or text template that can be expanded into a longer text. 11. What do you inline function?

 

A function definition such that each call to the function is in effect replaced by the statements that define the function.

 

12. What are the situations that inline functions may not work?

1. For function returning values, if a loop, a switch, or a goto exists.

2. For function not returning values, if a return statement exists.

3. If function contains static variables.

4. If inline functions are recursive.

13.            What are pointers?

 

A pointer is a variable that holds a memory address. This address is the location of another object in memory.

 

14.What are pointer operators? The pointer operators are * and &.

The & is a unary operator that returns the memory address of its operand.

 

The * is a unary operator that returns the value located at the address that follows. Example: char*p; // declaration of pointer p

 

char c=a;

 

p=&c; //address of variable c is assigned to pointer p cout<<”*p=”<<*p; // output:*p=a

 

15.What is meant by storage class specifiers?

 

Storage class specifiers tell the compiler how to store the subsequent variable. There are five storage class specifiers supported by C++:

 

i. extern ii. static iii.register iv. auto v.mutable

16.What is the use of ‘extern’ variables?

 

In a multifile program, we can declare all of the global variables in one file and use extern declarations in the other without defining it again.

 

The extern keyword has this general form: extern var-list;

 

17. what is function?

 

Functions are the building blocks of C++ and the place where all program activity occurs. The general form is

 

ret-type function-name(parameter list) { body of the function }

 

The ret-type specifies the type of data that the function returns. The parameter list is a comma-separated list of variable names and their associated types that receive the values of the arguments when the function is called. When the function is called the

 

control is transferred to the first statement in the body.

18. What are the two ways to pass arguments to the function?

 

Call by value: This method copies the value of an argument into the formal parameter of the function.

 

Call by reference: This method copies the address of an argument into the formal parameter of the function.

 

19. How to create call by reference?

We can create call by reference by passing a pointer (i.e. address of the argument ) to an argument, instead of argument itself.

 

Example:

void swap (int *x,int *y) {

 int temp;

 

temp=*x;

*x=*y;

*y=temp;

}

 

this function can be invoked with the addresses of the arguments as swap(&i,&j); //for interchanging the integer values i and j

 

20. What is the difference between endl and ‘\n'?

 

Using endl flushes the output buffer after sending a '\n', which means endl is more expensive in performance. Obviously if you need to flush the buffer after sending a '\n', then use endl; but if you don't need to flush the buffer, the code will run faster if you use '\n'.

 

21 What is the use of reference variables?

 

A reference variable provides an alias (alternate name) for a previously define variable. A reference variable is created as follows:

 

Datatype & reference-name =variablename; Example: int i=10;

 

int &sum=i; cout<<sum; // output:10 sum=100;

 

cout<<i; // output:100

22. Define keywords?

 

Keywords are explicitly reserved identifiers and cannot be used as names for the program variables or other user defined program elements.

 

23. Why do we need the preprocessor directive #include <iostream.h>?

 

This directive causes the preprocessor to add the contents of the iostream.h file to the program. It contains the declarations for the identifier cout and the operator <<. It contains function prototypes for the standard input output functions.

 

24.What is the use of return statement in main() function?

 

In C++, main() returns an integer type value to the operating system. Therefore, every main() in C++ should end with a return(0) statement; otherwise a warning or an error might occur.

 

25. How does a main() function in C++ differ from main() in C?

 

In C++, main() returns an integer type value to the operating system but in C , main() returns nothing to operating system by default.

 

26. What is formal parameter?

 

If a function is to use arguments , it must declare variables that will accept        the values of the

arguments. These variables are called the formal parameters of the

function.

 

Example : int max(int a , int b) // Variables a and b are formal parameter{ if(a>b) return a; return b; }

 

27. What is global variable?

Global variables are known throughout the program and may be used by any

piece of code. Also, they will hold their value throughout the program s execution.

28 What is the use of exit( ) function?

 

The exit( ) function causes immediate termination of the entire program, forcing a return to the operating system.

 

The general form :

Void exit(int return code);

 

The value of return code is returned to the calling process, which is usually the operating system. Zero is generally used as a return code to indicate normal program termination.

 

29. What is the use of break and continue statements?

 

Break is used to terminate a case in the switch statement. Force immediate termination of a loop, bypassing the normal loop conditional test.

 

Continue is used to force the next iteration of the loop to take place, skipping any code in between.

 

Study Material, Lecturing Notes, Assignment, Reference, Wiki description explanation, brief detail
Object Oriented Programming(OOP) : Overview : Important Short Questions and Answers: Object Oriented Programming(OOP) - Overview |


Privacy Policy, Terms and Conditions, DMCA Policy and Compliant

Copyright © 2018-2023 BrainKart.com; All Rights Reserved. Developed by Therithal info, Chennai.