Pages

Tuesday, September 20, 2011

Basics in C++

1.  Difference between C and C++

*C++ is Object Oriented.

*C++ uses bottom-up approach, While C uses top-down approach.

*C++ supports function overloading.

* Reference variable can be used in C++, Whereas C does not support.

*C++ support Classes

*C++ supports exception handling.

2. Operators that can not be overloaded in c++ are

* .(dot)

* ::

* ?:(ternary operator)

* sizeof()

3. Datatypes are

char – 1 byte

int – 2 bytes

short int – 2 bytes

float – 4 bytes

long int – 4 bytes

double – 8 bytes

4. Scope of variable
View Raw Code?

    #include<iostream.h>;
    int a; //<strong> Global variable</strong>
    void main()
    {
    int b; // <strong>Local Variables</strong>
    static int c; // Static variable, which is initialized to 0 automatically
    cout<<c;
    }

Output

0

5. = is used for assigning value to the variable

6. == is used for comparison

7. Types of operators

*Arithmetic operator (+,-,*,/,%)

*Compound assignment (+=, -=, *=, /=, %=, >>=, <, =, <= )

*Bitwise Operators ( &, |, ^, ~, <> )

*Logical operators ( !, &&, || )

* Conditional or Ternary operator (?:)

*sizeof() operator

* Dereference operator (.*)

* Scope resolution operator (::)

8. Basic input statement is “cin” and output statement is “cout”

9. Control structures

*simple if

* if….. else

*switch ()

*while()

*do….. while()

*for(;;)

*jump

*break

*continue

10. Call by value

The Value of the argument can be changed in the calling function, but its scope is within that calling function only.

11. Call by reference

The value of the argument is passed with address, so it’ll affect in both called function and calling function

12. Array is the group of elements of same datatype.

eg.int a[5]- allocates memory and store 5 integer value.

13.  We can use Multi Dimensional array.

eg. int matrixA[3][3] – in this we can store 9 elements.

14. A string is defined as array of characters which is enclosed within double quotes.

eg. char name= “Tech Twinklers”;

15.  Pointer is an address of variable.

16. A class is a collection of data variables and member function.

17.  An object is the instance of a class

18. There are three access specifiers, they are

*private, which is accessible only within its declared class

*protected, which can be accessed in its own class and in its inherited class.

*public, which can be accessed throughout the program.

19. Types of inheritance

Simple inheritance- Inherit the property of one base class

Multiple inheritance- Inherit the property from more than one base class.

Multi-Level inheritance

Hybrid inheritance

20. Polymorphism is the ability to overload the operator and functions.

21.  In function overloading, the function name will be same, but it differ in number of arguments and its types.

 

1 comment:

  1. Job Openings in Genpact
    http://job-openings-india.blogspot.in/2009/06/genpact-gecis.html

    ReplyDelete