Monday, October 31, 2016

cpp-page3

16. Explain what are Access specifiers in C++ class? What are the types?

Ans:
Access specifiers determine the access rights for the statements or functions that follow it until the end of class or another specifier is included. Access specifiers decide how the members of the class can be accessed. There are three types of specifiers

• Private
• Public
• Protected

17. Explain what are Operators and explain with an example?

Ans:
Operators are specific operands in C++ that is used to perform specific operations to obtain a result. The different types of operators available for C++ are Assignment Operator, Compound Assignment Operator, Arithmetic Operator, Increment Operator and so on.

For example arithmetic operators, you want to add two values a+b

#include
Using namespace std;
main ()
{
int a= 21 ;
int b= 10 ;
int c;
c= a + b;
cout << “Line 1- Value of c is : ” << c << endl ;
return 0;
}

18. Explain what is a reference variable in C++?

Ans:
A reference variable is just like a pointer with few differences. It is declared using & Operator. In other words, reference is another name for an already existing variable.

19. Explain what is Polymorphism in C++?

Ans:
Polymorphism in C++ is the ability to call different functions by using only one type of the function call. Polymorphism is referred to codes, operations or objects that behave differently in a different context.

For example, the addition function can be used in many contests like

• 5+5 :  Integer addition
• Medical+Internship : The same ( + ) operator can be used with different meaning with strings
• 3.14 + 2.27 : The same ( + ) operator can be used for floating point addition

20. Explain what is C++ exceptional handling?

Ans:
The problem that arises during execution of a program is referred as exceptional handling. The exceptional handling in C++ is done by three keywords.

• Try: It identifies a block of code for which particular exceptions will be activated
• Catch: The catch keyword indicates the catching of an exception by an exception handler at the place in a program
• Throw: When a problem exists while running the code, the program throws an exception



21.  Mention what are the types of Member Functions?

Ans:
The types of member functions are

• Simple functions
• Static functions
• Const functions
• Inline functions
• Friend functions

22. Explain what is multi-threading in C++?

Ans:
To run two or more programs simultaneously multi-threading is useful. There are two types of

• Process-based: It handles the concurrent execution of the program
• Thread-based: It deals with the concurrent execution of pieces of the same program

23. Explain what is upcasting in C++?

Ans:
Upcasting is the act of converting a sub class references or pointer into its super class reference or pointer is called upcasting.

24. Explain what is pre-processor in C++?

Ans:
Pre-processors are the directives, which give instruction to the compiler to pre-process the information before actual compilation starts.

25. What is difference between C and C++ ?

Ans:
C++ is Multi-Paradigm ( not pure OOP, supports both procedural and object oriented) while C follows procedural style programming.

In C data security is less, but in C++ you can use modifiers for your class members to make it inaccessible from outside.

C follows top-down approach ( solution is created in step by step manner, like each step is processed into details as we proceed ) but C++ follows a bottom-up approach ( where base elements are established first and are linked to make complex solutions ).
C++ supports function overloading while C does not support it.

C++ allows use of functions in structures, but C does not permit that.

C++ supports reference variables ( two variables can point to same memory location ). C does not support this.


C does not have a built in exception handling framework, though we can emulate it with other mechanism. C++ directly supports exception handling, which makes life of developer easy.



<Back  I  Next>


EmoticonEmoticon