C++ Interview Questions and Answers
1. 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 << \",\";
2. ISO layers and what layer is the IP operated from?
cation, Presentation, Session, Transport, Network, Data link and Physical. The IP is operated in the Network layer.
3. Write a program that ask for user input from 5 to 9 then calculate the average?
A.int main()
{
int MAX=4;
int total =0;
int average=0;
int numb;
cout << "Please enter your input from 5 to 9";
cin << numb;
if((numb < 5)&&(numb < 9))
cout << "please re type your input";
else
for(i=0;i < =MAX; i++)
{
total = total + numb;
average= total /MAX;
}
cout << "The average number is" << average << endl;
return 0;
}
4. Can you be bale to identify between Straight- through and Cross- over cable wiring? and in what case do you use Straight- through and Cross-over?
Straight-through is type of wiring that is one to to one connection Cross- over is type of wiring which those wires are got switched
We use Straight-through cable when we connect between NIC Adapter and Hub. Using Cross-over cable when connect between two NIC Adapters or sometime between two hubs.
5. If you hear the CPU fan is running and the monitor power is still on, but you did not see any thing show up in the monitor screen. What would you do to find out what is going wrong?
I would use the ping command to check whether the machine is still alive(connect to the network) or it is dead.
6. 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;
}
}
7. What is polymorphism?
Polymorphism is the idea that a base class can be inherited by several classes. A base class pointer can point to its child class and a base class array can store different child class objects.
8. 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.
9. How can you tell what shell you are running on UNIX system?
You can do the Echo $RANDOM. It will return a undefined variable if you are from the C-Shell, just a return prompt if you are from the Bourne shell, and a 5 digit random numbers if you are from the Korn shell. You could also do a ps -l and look for the shell with the highest PID.

delicious
digg
reddit
magnoliacom
newsvine
furl
google
yahoo
technorati
icerocket
pubsub
Recent comments