Monday, March 24, 2008

Some C++ interview questions @ Tech Interviews.com

Some C++ interview questions @ Tech Interviews.com
  1. What is a void return type?
  2. How is it possible for two String objects with identical values not to be equal under the == operator?
  3. What is the difference between a while statement and a do statement?
  4. Can a for statement loop indefinitely?
  5. How do you link a C++ program to C functions?
  6. How can you tell what shell you are running on UNIX system?
  7. How do you find out if a linked-list has an end? (i.e. the list is not a cycle)
  8. How do you write a function that can reverse a linked-list?
  9. Can a copy constructor accept an object of the same class as parameter, instead of reference of the object?
  10. What is a local class?
  11. What is a nested class?
  12. What are the access privileges in C++? What is the default access level?
  13. What is multiple inheritance(virtual inheritance)? What are its advantages and disadvantages?
  14. How do you access the static member of a class?
  15. What does extern int func(int *, Foo) accomplish?

18 Responses to “Some C++ interview questions”

  1. Nirmal Says:

    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.

  2. Nirmal Says:

    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

  3. Nirmal Says:

    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

  4. Nirmal Says:

    15:

    we can use the Extern keyword function in any other file. we can call that function indepedently

  5. Harunya Says:

    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

  6. Bakkialakshmi Says:

    12. What is multiple inheritance(virtual inheritance)? What are its advantages and disadvantages?

  7. Jeetendra Says:

    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.

  8. Jeetendra Says:

    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.

  9. Jeetendra Says:

    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.

  10. Abhishek Says:

    4. Can a for statement loop indefinitely?
    YES, leave conditional expression blank ie. in the format
    for(i=0;;i++)

  11. Abhishek Singh Says:

    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;
    }
    }

  12. Juan Guerrero Says:

    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. Ramon Zamora Says:

    #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.

  14. Zabin Says:

    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.

  15. PORCHELVI Says:

    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

  16. Manish Says:

    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

  17. vidhya Says:

    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.

  18. dina nassif Says:

    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
    #include
    #include
    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<

No comments:

如何发掘出更多退休的钱?

如何发掘出更多退休的钱? http://bbs.wenxuecity.com/bbs/tzlc/1328415.html 按照常规的说法,退休的收入必须得有退休前的80%,或者是4% withdrawal rule,而且每年还得要加2-3%对付通胀,这是一个很大...