we can find out the shell which we are currently working is in terminal we have like[bash/abc/home] here bash is the shell. so that you can find out like tat.
you have 3 access modifiers in C++ 1. private 2. public 3. protected. defaultly c++ variable are Private. Java variables arr Public. C# varibles are Virtual
Can a copy constructor accept an object of the same class as parameter, instead of reference of the object?
Yes it can accept but it will go on infinite loop.
static data member -you can access thru member function or thru class name using scope resolution operator.
static member function:-you can access thru class name using scope resolution operator.
How do you write a function that can reverse a linked-list?
Ans:
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;
}
Q. #5
You can do that by means of the extern "C" { } construct.
Q. #6
Easy, you could use the getenv function, like this:
#include
#include
int main(){
std::cout
Q. #7
Many ways to implement it, but you could basically add a counter to each node with initial value of 0, then after each node read increase its value, so before reading you compare if it has the same value or higher than the previous node then we’ve found a loop, if not (value = prev - 1), then increase the value counter + 1.
Q. #9
Depends on the compiler, whoever, the definition of copy constructor explicitly says that it can only have an const-reference of the same class as argument.
Q. #12
The access privileges are public, private and protected. public can be accessed from any subclass and even outside the scope of the class, protected can only be used from within the scope of the class and its subclasses, private can only be used within the scope of that class but is forbidden for any subclass. The default access privilege is private.
#13
In a diamond hierarchy, virtual inheritance allows a derive class “D” to share only one copy of the common base case “A”. This is done by using the keyword virtual on the declaration.
For example
class A{…}
class B : virtual public A {…}
class C : virtual public A {…}
class D : public B, public C {} // class D only contains one copy of A.
Advantage: The derived class contains only one copy of the base class.
Disadvantage: The runtime cost is similar to the one of a virtual function. The compiler inserts a pointer (in D) that points to the location of the base “A”. And it has to dereference it, whenever is needed.
What is multiple inheritance(virtual inheritance)? What are its advantages and disadvantages?
Multiple Inheritance means there is only one base class and multiple no. of derived class are inheriting it.
Virtual Inheritance: Suppose class A is inherited by class B and class C. Another class D is inheriting class B and C. Now class D is indirectly inheriting class A that to two times. This is an ambiguity. To avoid this we have amke the class A as Virtual base class and class B and C will have inherit is virtually. Now when D is inheriting both B and C, it will get only one copy of A rather than 2 copies(as in the earlier case). This virtual Inheritance.
3.What is the difference between a while statement and a do statement?
Ans:
while is first check the condition and execute the statements
but do first execute the statements then check the condition
Q: What is a void return type?
A: void return type indicates that the function returns nothing ( no value at all ). Although this should not be confused with the ” void * ” return type which is altogather different thing.
Q: How is it possible for two String objects with identical values not to be equal under the == operator?
A :
Q : What is the difference between a while statement and a do statement?
A : While checks the condition statement before the iteration whereas do checks the conditon statement after iteration.Thus do ensures that the loop block is executed at least once.
Q : Can a for statement loop indefinitely?
A : Yes . for (int i=0;i!=1;) cout
Check the next(pointer) of each node, if it is NULL that is the end node. Linked list will be a loop if there is no NULL value in any of the node’s pointer.
Hi
i wanna to ask aquistion , i’m try to do a programe to read from file expretion like this(create x [10,20,30]) and simulate  it in c++ cod here is my cod ,i’d be gratiful if any body help me to solve this problem.
//******************************************/
#include<iostream>
#include<fstream>
#include<vector>
using namespace std;
question 14.
Those Class which inherits the properties of one or more base class is called multiplae inheritance.
The class C inherits the properties of base class A & B. That means C is the derived class which inherits the properties of base class A & A.
Advantages: It inherits all properties of each & every base class which it can inherit.
Question 7.
Checking to see if a linked list ends:
- Check to see if there are loops in the linked list: Have one pointer incremented 1 node at a time, another one 2 nodes at a time. If the 2 node pointed passes the 1 node pointer, it has looped. If the pointer that increments 2 at a time reaches the end, there is no loop.
//given list head, returns the head of the reversed list
Node_ptr reverseList(Node_ptr head){
if (!head){ //if head is NULL
return head;
}
Node_ptr prev, curr;
curr = head;
prev = NULL;
while (curr->_next){ //if next element is not null
head = curr;
curr = curr->_next;
head->_next = prev;
prev = head;
}
curr->_next = prev;
return curr;
}
3.difference between while and do is ,in while statement , first it will check the condition ,if condition is true it will enter into the loop,false it will exit.but in do if condition is false ,at first iteration it will enter into loop.after it will check the condition.
#7: How do you find out if a linked-list has an end?
You can’t simply follow the next-pointers until you find a NULL-pointer. This would result in an infinite loop if you have a ring!
Linked lists can have three forms:
l1 -> l2 -> l3 -> l4 -> NULL Linear
l1 -> l2 -> l3 -> l4 -> l1 Closed ring
l1 -> l2 -> l3 -> l4 -> l2 Open ring
You must compare the pointer with the start-pointer to identify a Closed ring. This funktion also identifies Open rings:
int getListForm(ListElem *p0)
{
if (!p0 || !po->next)
return 0; // Linear
ListElem *p1=p0, *p2=p1->next;
bool bEven=true;
for (;;)
{
p2=p2->next;
if (p2==NULL)
return 1; // Linear
else if (p2==p0)
return 2; // Closed ring
else if (p2==p1)
return 3; // Open ring
bEven = !bEven;
if (bEven)
p1=p1->next; // Step every 2nd loop
}
}
p2 “moves twice as fast” as p1.
In an open ring, p2 will surely hit p1 after a finite number of loops because both will enter the closed loop in finite time.
28 Comments on Some C++ interview questions
for question no 6:
we can find out the shell which we are currently working is in terminal we have like[bash/abc/home] here bash is the shell. so that you can find out like tat.
question 12:
you have 3 access modifiers in C++ 1. private 2. public 3. protected. defaultly c++ variable are Private. Java variables arr Public. C# varibles are Virtual
14:
you can use the static memeber or method of a class in Main function jus call class name. method or member name. tats enough
15:
we can use the Extern keyword function in any other file. we can call that function indepedently
Question:1
void doesn’t return any value
Question:2
By using an operator overloading we find the strings are same or not
Question:3
while check the condition in entry,do-while check the condition at exit of the loop statement ie., do-while works atleast once
12. What is multiple inheritance(virtual inheritance)? What are its advantages and disadvantages?
What is a local class?
If a class is defined within a function that class is a local class which is local to the function and it can not be accessed outside the class.
Can a copy constructor accept an object of the same class as parameter, instead of reference of the object?
Yes it can accept but it will go on infinite loop.
What is a nested class?
Class within a class.
How do you access the static member of a class?
static data member -you can access thru member function or thru class name using scope resolution operator.
static member function:-you can access thru class name using scope resolution operator.
4. Can a for statement loop indefinitely?
YES, leave conditional expression blank ie. in the format
for(i=0;;i++)
How do you write a function that can reverse a linked-list?
Ans:
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;
}
}
Q. #5
You can do that by means of the
extern "C" { }construct.Q. #6
Easy, you could use the getenv function, like this:
#include
#include
int main(){
std::cout
Q. #7
Many ways to implement it, but you could basically add a counter to each node with initial value of 0, then after each node read increase its value, so before reading you compare if it has the same value or higher than the previous node then we’ve found a loop, if not (value = prev - 1), then increase the value counter + 1.
Q. #9
Depends on the compiler, whoever, the definition of copy constructor explicitly says that it can only have an const-reference of the same class as argument.
Q. #12
The access privileges are public, private and protected. public can be accessed from any subclass and even outside the scope of the class, protected can only be used from within the scope of the class and its subclasses, private can only be used within the scope of that class but is forbidden for any subclass. The default access privilege is private.
#13
In a diamond hierarchy, virtual inheritance allows a derive class “D” to share only one copy of the common base case “A”. This is done by using the keyword virtual on the declaration.
For example
class A{…}
class B : virtual public A {…}
class C : virtual public A {…}
class D : public B, public C {} // class D only contains one copy of A.
Advantage: The derived class contains only one copy of the base class.
Disadvantage: The runtime cost is similar to the one of a virtual function. The compiler inserts a pointer (in D) that points to the location of the base “A”. And it has to dereference it, whenever is needed.
What is multiple inheritance(virtual inheritance)? What are its advantages and disadvantages?
Multiple Inheritance means there is only one base class and multiple no. of derived class are inheriting it.
Virtual Inheritance: Suppose class A is inherited by class B and class C. Another class D is inheriting class B and C. Now class D is indirectly inheriting class A that to two times. This is an ambiguity. To avoid this we have amke the class A as Virtual base class and class B and C will have inherit is virtually. Now when D is inheriting both B and C, it will get only one copy of A rather than 2 copies(as in the earlier case). This virtual Inheritance.
3.What is the difference between a while statement and a do statement?
Ans:
while is first check the condition and execute the statements
but do first execute the statements then check the condition
Q: What is a void return type?
A: void return type indicates that the function returns nothing ( no value at all ). Although this should not be confused with the ” void * ” return type which is altogather different thing.
Q: How is it possible for two String objects with identical values not to be equal under the == operator?
A :
Q : What is the difference between a while statement and a do statement?
A : While checks the condition statement before the iteration whereas do checks the conditon statement after iteration.Thus do ensures that the loop block is executed at least once.
Q : Can a for statement loop indefinitely?
A : Yes . for (int i=0;i!=1;) cout
How do you find out if a linked-list has an end?
Check the next(pointer) of each node, if it is NULL that is the end node. Linked list will be a loop if there is no NULL value in any of the node’s pointer.
Hi
i wanna to ask aquistion , i’m try to do a programe to read from file expretion like this(create x [10,20,30]) and simulate  it in c++ cod here is my cod ,i’d be gratiful if any body help me to solve this problem.
//******************************************/
#include<iostream>
#include<fstream>
#include<vector>
using namespace std;
class MemoryTableEntry{
public :
 char vn;
 vector* list; //eh da?
};class parser(){ MemoryTableEntry memroyTable[100];
ÂÂ
 static int variable_index = 0; void parse(string str){
  if(c==create){  char vn=’x';  vector* v=new vector();  MemoryTableEntry entry;
 ÂÂ
  entry.vn = vn;
  enrty.list = v;
 ÂÂ
  memroyTable[variable_index] = entry;
  variable_index++;
  }
 }
ÂÂ
};
void main(){
 fstream f1("F://f1.txt");
  char c;
 while(!f1.eof()){
   f1>>c;
 cout<<c;
 }
//**************************************/
question 14.
Those Class which inherits the properties of one or more base class is called multiplae inheritance.
The class C inherits the properties of base class A & B. That means C is the derived class which inherits the properties of base class A & A.
Advantages: It inherits all properties of each & every base class which it can inherit.
#4
for(;;)
answer to:
How is it possible for two String objects with identical values not to be equal under the == operator?
the == operator looks for string variables in the same memory LOCATION on your hard drive, not for the same values (ie same letters, spaces, etc)
question #6 :
by using the echo $SHELL command
ANSWER 1
Void is a empty data type , which is used as an access specifier but not as a variable declaration. :)
ANSWER 2
Use operator Overloading
ANSWER 3
while First check the condition then execute Statement
but Do-While atleast one time runs the loop, then check the condition . :)
ANSWER 4
of course
for(int i=0;;i++)
ANSWER 5
Use Extern c .
ANSWER 6
:( sorry dont no !
IF U HAVE NE MORE QUESTION < SEND ME ON MY MAIL anuj_2cute@yahoo.co.in
BREAK;
Question 7.
Checking to see if a linked list ends:
- Check to see if there are loops in the linked list: Have one pointer incremented 1 node at a time, another one 2 nodes at a time. If the 2 node pointed passes the 1 node pointer, it has looped. If the pointer that increments 2 at a time reaches the end, there is no loop.
Question 8:
———–
Function to reverse a list:
#include
typedef struct Node *Node_ptr;
struct Node{
int _data;
Node_ptr _next;
};
//given list head, returns the head of the reversed list
Node_ptr reverseList(Node_ptr head){
if (!head){ //if head is NULL
return head;
}
Node_ptr prev, curr;
curr = head;
prev = NULL;
while (curr->_next){ //if next element is not null
head = curr;
curr = curr->_next;
head->_next = prev;
prev = head;
}
curr->_next = prev;
return curr;
}
3.difference between while and do is ,in while statement , first it will check the condition ,if condition is true it will enter into the loop,false it will exit.but in do if condition is false ,at first iteration it will enter into loop.after it will check the condition.
12.nested class means ,which is the class inside of the class .
#7: How do you find out if a linked-list has an end?
You can’t simply follow the next-pointers until you find a NULL-pointer. This would result in an infinite loop if you have a ring!
Linked lists can have three forms:
l1 -> l2 -> l3 -> l4 -> NULL Linear
l1 -> l2 -> l3 -> l4 -> l1 Closed ring
l1 -> l2 -> l3 -> l4 -> l2 Open ring
You must compare the pointer with the start-pointer to identify a Closed ring. This funktion also identifies Open rings:
int getListForm(ListElem *p0)
{
if (!p0 || !po->next)
return 0; // Linear
ListElem *p1=p0, *p2=p1->next;
bool bEven=true;
for (;;)
{
p2=p2->next;
if (p2==NULL)
return 1; // Linear
else if (p2==p0)
return 2; // Closed ring
else if (p2==p1)
return 3; // Open ring
bEven = !bEven;
if (bEven)
p1=p1->next; // Step every 2nd loop
}
}
p2 “moves twice as fast” as p1.
In an open ring, p2 will surely hit p1 after a finite number of loops because both will enter the closed loop in finite time.