C++ Interview Questions
Good C interview Questions
- How do you decide which integer type to use?
- What should the 64-bit integer type on new, 64-bit machines be?
- What’s the best way to declare and define global variables?
- What does extern mean in a function declaration?
- What’s the auto keyword good for?
- I can’t seem to define a linked list node which contains a pointer to itself.
- How do I declare an array of N pointers to functions returning pointers to functions returning pointers to characters?
- How can I declare a function that returns a pointer to a function of its own type?
C interview question
1. What will print out?
main()
{
char *p1=“name”;
char *p2;
p2=(char*)malloc(20);
memset (p2, 0, 20);
while(*p2++ = *p1++);
printf(“%s\n”,p2);
}
Answer:empty string.
2. What will be printed as the result of the operation below:
main()
{
int x=20,y=35;
x=y++ + x++;
y= ++y + ++x;
printf(“%d%d\n”,x,y);
}
Answer : 5794
3. What will be printed as the result of the operation below:
main()
{
int x=5;
printf(“%d,%d,%d\n”,x,x< <2,x>>2);
}
Answer: 5,20,1
4. What will be printed as the result of the operation below:
C++ Code Examples
Q: Write a short code using C++ to print out all odd number from 1 to 100 using a for loop(Asked by Intacct.com people)
for( unsigned int i = 1; i < = 100; i++ ) if( i & 0×00000001 ) cout << i<<",";
ISO layers and what layer is the IP operated from?( Asked by Cisco system people)
cation, Presentation, Session, Transport, Network, Data link and Physical. The IP is operated in the Network layer.
3.Q: Write a program that ask for user input from 5 to 9 then calculate the average( Asked by Cisco system people)
C++ Interviews Question
- In C++, what is the difference between method overloading and method overriding?Overloading a method (or function) in C++ is the ability for functions of the same name to be defined as long as these methods have different signatures (different set of parameters). Method overriding is the ability of the inherited class rewriting the virtual method of the base class.
- What methods can be overridden in Java? In C++ terminology, all public methods in Java are virtual. Therefore, all Java methods can be overwritten in subclasses except those that are declared final, static, and private.
C++ Object Oriented Interviews Questions
Q. What is pure virtual function?
A class is made abstract by declaring one or more of its virtual functions to be pure. A pure virtual function is one with an initializer of = 0 in its declaration
Q. Write a Struct Time where integer m, h, s are its members
struct Time
{
int m;
int h;
int s;
};
ow do you traverse a Btree in Backward in-order?
Process the node in the right subtree
Process the root
Process the node in the left subtree
Q. What is the two main roles of Operating System?
As a resource manager
As a virtual machine