Prepare Interview

Mock Exams

Make Homepage

Bookmark this page

Subscribe Email Address

C++ Interview Questions and Answers

Test your skills through the online practice test: C++ Quiz Online Practice Test

Related differences

C vs C++Java vs C++

Ques 6. 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.

Is it helpful? Add Comment View Comments
 

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


void reverselist(void)
{
if(head==0)
return;
if(head->next==0)
return;
if(head->next==tail)
{
head->next = 0;
tail->next = head;
}
else
{
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;
}
}

Is it helpful? Add Comment View Comments
 

Ques 8. 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.

Is it helpful? Add Comment View Comments
 

Ques 9. Write a program that ask for user input from 5 to 9 then calculate the average


#include "iostream.h"
int main() {
int MAX = 4;
int total = 0;
int average;
int numb;
for (int i=0; i<MAX; i++) {
cout << "Please enter your input between 5 and 9: ";
cin >> numb;
while ( numb<5 || numb>9) {
cout << "Invalid input, please re-enter: ";
cin >> numb;
}
total = total + numb;
}
average = total/MAX;
cout << "The average number is: " << average << "n";
return 0;
}

Is it helpful? Add Comment View Comments
 

Ques 10. 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 << ",";
 

Is it helpful? Add Comment View Comments
 

4) Write a program that ask for user input from 5 to 9 then calculate the average 5) Write a short code using C++ to print out all odd number from 1 to 100 using a for loop " />

Most helpful rated by users:

©2024 WithoutBook