Saturday, August 28, 2010

An Overview of C++

1) What is a structured language?

The languages such as C and PASCAL are structure languages, which are characterized by their support for stand-alone subroutines, local variables, rich control constructs and their lack of reliance upon the GOTO statements.

2) What is the basic difference between the object oriented programming language and the structured pro-gramming language?

In structured programming language, the program is organized around the code, means, program is struc-tures into subroutines or functions which act on data, on the other hand the object oriented programming you define the data type, which will define how can access that data, in the sense the program is organized around data.

3) What are the characteristics of C++ or object oriented programming language?

The three main characteristics of an object oriented programming language is Encapsulation, Polymorphism and Inheritance. The class definitions explains encapsulation, the function and operator overloading explains polymorphism and the

4) What is Encapsulation in Object oriented programming language?

Encapsulation is a mechanism that binds together the code and the data it manipulates, and keep both safe from outside interference and misuse, the private data or code is accessible only within that object or class and public data or code can be accessed from outside, which gives an interface to the outside world to access the inside code and data of object.

5) What is polymorphism and what kind of polymorphisms are supported in C++?

One interface, multiple methods, in simple terms it is an attribute that allows one interface to control access to a general class of actions, the specific action selected is determined by the exact nature of the situation. Compiler will select the method appropriate for a particular situation, and programmers don’t need do it manually.

C++ supports both run time and compile time polymorphism. Compile time using function overloading and operator overloading. Run time using virtual functions.

6) What is inheritance in object oriented programming languages?

This is a concept of classification, where an objects property can be derived from another object, and it only needs to define those qualities that make it unique within its class. Example the Apple belongs to the class fruits and fruits belongs to class food etc.
7) How does bool data type is defined in C++?

There is standard Boolean data type in C++, which takes value true or false, true being 1 and false being zero automatic conversion to integer is supported, all non-zero value is treated as true and zero as false.

8) What is a class in C++

Class is a means to define an objects outline using data and code and access permissions, this is the inheri-tance is achieved in C++.

9) What is function overloading?

When you have similar tasks to be performed then you can declare functions with same name, keeping the number of parameters and /or their type different. Then the compiler will select the right function depending on the situation. This process is called function overloading. It is not only enough to keep the return type different. This is a polymorphism feature of C++. The other polymorphism feature available in C++ is operator overloading. There is run time polymorphism also using virtual functions using inheritance and derived class.

10) What are constructor and destructors?

It is very often that we need to initialize the class before we can use them, so C++ provides a way to auto-matically do it using constructor and then de-allocate any resources in the destructor. The constructor has same name as that of the class and it does not have any return type, because constructor cannot return anything. It should also be public member function of the class, because objects of that class needs to be defined in public scope. The same rules apply to the destructors also, destructors names has additional ~ at the beginning. The constructors are called when the declaration statements are executed, and destructors are called when the objects are destroyed

No comments:

Post a Comment