C++ Programming

1. Computer Programming 2. History of Prog.Language 3. Introduction to C++ 4. OOPS 5. Features of C++ 6. Starting Turbo C++ 7. C++ Tokens 8. Basic requirment of C++ 9. Comments 10. My First Program in C++ 11. Line Break 12. C++ Escape Sequence 13. Constants or Literals 14. Variable in C++ 15. Data Types in C++ 16. Range of data types in C++ 17. Declare Variables 18. Reserved Key Words 19. cout<< 20. Chained & Embedded state 21. Prog.to print sum of 2 nos 22. cin>> 23. Prg.to print sum & average 24. Area & Perimeter of Rectangle 25. Area Circumference of Circle 26. Prg.for Simple Calculator 27. Operatos in C++ 28. Ex. Of Operators 29. Swap two numbers 30. Hierarchy of Operators 31. if( ) statement 32. Prg.to check +ve,-ve or zero 33. if..else statement 34. Prg.to check Odd or Even 35. Prg.to print larger of 2 nos 36. Prg.to print largest of 3 nos 37. Prg.to check divisibility 38. Prg.to check print range 39. for. . . loop statement 40. prg.to print series of nos 41. Prg.to check divisibility 42. prg.to print sum of series 43. Prg.to print Pyramid 44. prg.for Factorial 45. prg.to fill screen 46. prg.for largest/smallest no 47. prg.to print reverse no 48. prg.to add each digit 49. prg.for sum of factorial 50. prg.for fibonacci series 51. prg.to check Prime nos 52. prg. Prime no from 1 to 100 53. prg.Specified Prime nos 54. while( ) statement 55. do. . While statement 56. goto statement 57. break & continue statement 58. switch case statement 59. Array in C++ 60. print reverse order using array 61. Ascending/Descending order 62. prg.to search no in Array 63. Double Dimension Array 64. String in C++ 65. String with spaces in C++ 66. prg.to print string in reverse 67. prg.to count A,E,I,O,U vowel 68. Function( ) in C++ 69. Function program examples 70. General Purpose Programs 71. Loan & EMI calculation prg. 72. Table print prg. 73. Leap year program 74. lower to UPPER case prg. 75. Age Distribution prg. 76. Bank note calculation prg. 77. Simple Interest prg. 78. Compound Interest prg. 79. Simple Depreciation prg. 80. Reducing bal.Depreciation prg. 81. Marksheet prg. 82. Income Tax prg. 83. Time calculator prg. 84. Distance converter prg. 85. Volume Air Calculation prg. 86. Time to fill Water Tank prg. 87. Salary Calculation prg. 88. Total Sale Calculation prg. 89. Male/Female percentage prg. 90. Library Rent prg. 91. Office Expence prg. 92. Total Salary Calculation prg. 93. Profit or Loss prg. 94. Total Profit/Loss prg. 95. Convert Amt to Word. 96. ASCII Table 97. C++ Operators 98. C & C++ Reserved Keyword 99. C & C++ Pre-Define Function 100. C++ Interview Part1 101. C++ Interview Part2 102. C++ Interview Part3 103. C++ Interview Part4 104. C++ Interview Part5 105. C++ Interview Part6 106. C++ Interview Part7 107. C++ Interview Part8 108. C++ Interview Part9 109. C++ Interview Part10 110. C++ Interview Part11 111. C++ Interview Part11
Pr.Pg Next Pg

C++ Interview Question and Answers Part 1

1.What is C++?

  • Released in 1985, C++ is an object-oriented programming language created by Bjarne Stroustrup.

  • C++ maintains almost all aspects of the C language, while simplifying memory management and adding several features - including a new datatype known as a class (you will learn more about these later) - to allow object-oriented programming.

  • C++ maintains the features of C which allowed for low-level memory access but also gives the programmer new tools to simplify memory management.

  • C++ used for:

  • C++ is a powerful general-purpose programming language. It can be used to create small programs or large applications.

  • It can be used to make CGI scripts or console-only DOS programs. C++ allows you to create programs to do almost anything you need to do.

  • The creator of C++, Bjarne Stroustrup, has put together a partial list of applications written in C++.


2.How do you find out if a linked-list has an end? (i.e. the list is not a cycle)

  • You can find out by using 2 pointers. One of them goes 2 nodes each time.

  • The second one goes at 1 nodes each time. If there is a cycle, the one that goes 2 nodes each time will eventually meet the one that goes slower.

  • If that is the case, then you will know the linked-list is a cycle.


3.What is the difference between realloc() and free()?

  • The free subroutine frees a block of memory previously allocated by the malloc subroutine.

  • Undefined results occur if the Pointer parameter is not a valid pointer.

  • If the Pointer parameter is a null value, no action will occur.

  • The realloc subroutine changes the size of the block of memory pointed to by the Pointer parameter to the number of bytes specified by the Size parameter and returns a new pointer to the block.

  • The pointer specified by the Pointer parameter must have been created with the malloc, calloc, or realloc subroutines and not been deallocated with the free or realloc subroutines.

  • Undefined results occur if the Pointer parameter is not a valid pointer.


4.What is the difference between declaration and definition?

  • The declaration tells the compiler that at some later point we plan to present the definition of this declaration.

void stars () //function declaration

The definition contains the actual implementation.


void stars () // declarator


for(int j=10; j > =0; j--) //function body

cout << *;

cout << endl; }


5.What are the advantages of inheritance?

  • It permits code reusability.

  • Reusability saves time in program development.

  • It encourages the reuse of proven and debugged high-quality software, thus reducing problem after a system becomes functional.


6.How do you write a function that can reverse a linked-list?

void reverselist(void)








head->next = 0;

tail->next = head;




node* pre = head;

node* cur = head->next;

node* curnext = cur->next;

head->next = 0;

cur-> next = head;


for(; curnext!=0; )


cur->next = pre;

pre = cur;

cur = curnext;

curnext = curnext->next;



curnext->next = cur;




7.What do you mean by inline function?

  • The idea behind inline functions is to insert the code of a called function at the point where the function is called.

  • If done carefully, this can improve the application's performance in exchange for increased compile time and possibly (but not always) an increase in the size of the generated binary executables.


8.Write a short code using C++ to print out all odd number from 1 to 100 using a for loop

for( unsigned int i = 1; i < = 100; i++ )

if( i & 0x00000001 )

cout << i << \",\";


9.What is public, protected, private?

  • Public, protected and private are three access specifier in C++.

  • Public data members and member functions are accessible outside the class.

  • Protected data members and member functions are only available to derived classes.

  • Private data members and member functions canít be accessed outside the class. However there is an exception can be using friend classes.

  • Write a function that swaps the values of two integers, using int* as the argument type.


void swap(int* a, int*b) {

int t;

t = *a;

*a = *b;

*b = t;


10.What are Function of C++?

  • Till now we have worked with main() function only. It is one and only function that consists of header and body of program. Now its time to use another function.

  • For smaller program main() function is sufficient, while for complex and bigger program we can write separate functions and call it. This is known as function call, which is point at which function is called, where by actual function is inserted in program during linking to library files.

  • When program becomes large, it becomes difficult to manage it as single program. Hence one can divide program into smaller parts known as functions.

  • Function act individually and gives result.

  • Similarly, statements required repeatedly within programs can be written once as function, and can be called many times.

  • A function is a self-contained program that carries out some specific task.

  • Each C++ Program consists of one or more functions.

  • One of this function must be main(). Program execution begin from main( ). And each function in program is called in the sequence specified by function call in main().

  • Additional functions will be subordinate to main().

  • After each function completes its task, control returns to main(). When all statements and other function calls completes, the program ends.

Pr.Pg border                                              Next Pg