• +91 9971497814
  • info@interviewmaterial.com

Computer Interview Questions Answers

CPlusPlus Interview Questions Answers

Question - 111 : - How do you traverse a Btree in Backward in-order?

Answer - 111 : - Process the node in the right subtree Process the root Process the node in the left subtree

Question - 112 : - What is the difference between declaration and definition?

Answer - 112 : - The declaration tells the compiler that at some later point we plan to present the definition of this declaration. E.g.: void stars () //function declaration The definition contains the actual implementation. E.g.: void stars () // declarator { for(int j=10; j > =0; j--) //function body cout << *; cout << endl; }

Question - 113 : - void main() { char *cptr = 0?2000; long *lptr = 0?2000; cptr++; lptr++; printf(” %x %x”, cptr, lptr); } Will it execute or not?

Answer - 113 : - 3. For Q2: As above, won’t compile because main must return int. Also, 0×2000 cannot be implicitly converted to a pointer (I assume you meant 0×2000 and not 0?2000.) 2. Not Excute. Compile with VC7 results following errors: error C2440: ‘initializing’ : cannot convert from ‘int’ to ‘char *’ error C2440: ‘initializing’ : cannot convert from ‘int’ to ‘long *’ Not Excute if it is C++, but Excute in C. The printout: 2001 2004 3. In C++ [$]> g++ point.c point.c: In function `int main()’: point.c:4: error: invalid conversion from `int’ to `char*’ point.c:5: error: invalid conversion from `int’ to `long int*’ in C ———————————– [$] etc > gcc point.c point.c: In function `main’: point.c:4: warning: initialization makes pointer from integer without a cast point.c:5: warning: initialization makes pointer from integer without a cast [$] etc > ./a.exe 2001 2004

Question - 114 : - What is a COPY CONSTRUCTOR and when is it called?

Answer - 114 : - A copy constructor is a method that accepts an object of the same class and copies it’s data members to the object on the left part of assignement: class Point2D{ int x; int y; public int color; protected bool pinned; public Point2D() : x(0) , y(0) {} //default (no argument) constructor public Point2D( const Point2D & ) ; }; Point2D::Point2D( const Point2D & p ) { this->x = p.x; this->y = p.y; this->color = p.color; this->pinned = p.pinned; } main(){ Point2D MyPoint; MyPoint.color = 345; Point2D AnotherPoint = Point2D( MyPoint ); // now AnotherPoint has color = 345

Question - 115 : - What is an accessor?

Answer - 115 : - An accessor is a class operation that does not modify the state of an object. The accessor functions need to be declared as const operations

Question - 116 : - What’s the auto keyword good for?

Answer - 116 : - 1.  Not much. It declares an object with automatic storage duration. Which means the object will be destroyed at the end of the objects scope. All variables in functions that are not declared as static and not dynamically allocated have automatic storage duration by default. For example int main() { int a; //this is the same as writing “auto int a;” } 2. Local variables occur within a scope; they are “local” to a function. They are often called automatic variables because they automatically come into being when the scope is entered and automatically go away when the scope closes. The keyword auto makes this explicit, but local variables default to auto auto auto auto so it is never necessary to declare something as an auto auto auto auto.

Question - 117 : - Describe PRIVATE, PROTECTED and PUBLIC – the differences and give examples.

Answer - 117 : - class Point2D{ int x; int y; public int color; protected bool pinned; public Point2D() : x(0) , y(0) {} //default (no argument) constructor }; Point2D MyPoint; You cannot directly access private data members when they are declared (implicitly) private: MyPoint.x = 5; // Compiler will issue a compile ERROR //Nor yoy can see them: int x_dim = MyPoint.x; // Compiler will issue a compile ERROR On the other hand, you can assign and read the public data members: MyPoint.color = 255; // no problem int col = MyPoint.color; // no problem With protected data members you can read them but not write them: MyPoint.pinned = true; // Compiler will issue a compile ERROR bool isPinned = MyPoint.pinned; // no problem

Question - 118 : - What is the two main roles of Operating System?

Answer - 118 : - As a resource manager As a virtual machine

Question - 119 : - What is abstraction?

Answer - 119 : - Abstraction is of the process of hiding unwanted details from the user.

Question - 120 : - What is deadlock?

Answer - 120 : - Deadlock is a situation when two or more processes prevent each other from running. Example: if T1 is holding x and waiting for y to be free and T2 holding y and waiting for x to be free deadlock happens.

Computer Contributors

krishan
Rajeev Katiyar
Yes Baroda

Share your email for latest updates

Name:
Email:

Our partners