分类: C/C++
2011-04-01 01:04:10
1. Difference between heap and stack?
The stack is a place in the computer memory where all the variables that are declared and initialized before runtime are stored.
The heap is the section of computer memory where all the variables created or initialized at runtime are stored. heap is an area of memory used for dynamic memory allocation .
Stack:
- local variables (variables declared inside a function) are put on the stack - unless they are also declared as 'static' or 'register'
- function parameters are allocated on the stack
- local variables that are declared on the stack are not automatically initialized by the system so they usually have garbage in them until you set them
- variables on the stack disappear when the function exits (thus, if a function is called multiple times, it's local variables and parameters are recreated and destroyed each time the function is called end exited).
Heap:
- declared variables (as opposed to dynamically created ie new, malloc) are created on the heap before program execution begins, they exist the entire life of the program (although scope may prevent access to them - they still exist) and they are initialized to all zeros
- global variables are on the heap
- static local variables are on the heap (this is how they keep their value between function calls)
- memory allocated by new, malloc and calloc are on the heap
2. The difference between structs and classes in c++?
The members and base classes of a struct are public by default, while in class , they default to private . Note: you should make your base classes explicitly public , private , or protected , rather than relying on the defaults.
struct and class are otherwise functionally equivalent.
3. What is virtual function?
A virtual function is a member function that you expect to be redefined in derived classes.
4. How does virtual function implemented?
Vtable: http://blog.csdn.net/yyyy1985/archive/2009/05/07/4156746.aspx
5. What’s abstract class?
An abstract class, or abstract base class (ABC), is a class that cannot be instantiated.
Abstract classes are closely related to interfaces. They are classes that cannot be instantiated, and are frequently either partially implemented, or not at all implemented. One key difference between abstract classes and interfaces is that a class may implement an unlimited number of interfaces, but may inherit from only one abstract (or any other kind of) class.
6. What is pure virtual function?
An abstract class contains at least one pure virtual function. Specify a virtual function as pure by placing = 0 at the end of its declaration. You don't have to supply a definition for a pure virtual function.
7. What’s the difference between virtual function and pure virtual function?
There are two major differences between a virtual and a pure virtual function, these are below:
There CAN’T be a definition of the pure virtual function in the base class.
There MUST be a definition of the pure virtual function in the derived class.
In other words, because pure virtual function has to be declared as =0 in the base class without function body; and then be redefined in the derived class to override the declaration in base class.
8. What are the differences and similarities between thread and process?
Differences
In Space: Threads share the address space of the process that created it; Process have their own address.
Data Access: Threads have direct access to the data segment of its process; P rocesses have their own copy of the data segment of the parent process.
Commu: Threads can directly communicate with other threads of its process; processes must use inter-process communication to communicate with sibling processes .
Overhead: Threads have almost no overhead; processes have considerable overhead.
Creation/Call: New threads are easily created; new processes require duplication of the parent process.
Threads can exercise considerable control over threads of the same process; processes can only exercise control over child processes .
Interaction: Changes to the main thread (cancellation, priority change, etc.) may affect the behavior of the other threads of the process, changes to the parent process does not affect child processes .
Similarities:
Both have an id, set of registers, state, priority, and scheduling policy.
Both have attributes that describe the entity to the OS.
Both have an information block.
Both share resources with the parent process.
Both function as independent entities from the parent process.
The creator can exercise some control over the thread or process.
Both can change their attributes.
Both can create new resources.
Neither can access the resources of another process.
9. What’s the difference between mutex and semaphore?
A mutex is a binary semaphore, usually including extra features like ownership or priority inversion protection.
The differences between mutexes and semaphores are operating system dependent . Mutexes are meant to be used for mutual exclusion only and binary semaphores are meant to be used for event notification and mutual exclusion
10. What is the difference between new and operator new?
The C++ keyword "new" represents the new operator.It is used:
1. to allocate the memory
2. to call the constructor.
The (1)st job is done using C++'s inbuilt 'operator new'. (Bad overloading of terminologies!). The prototype of "operator new" is void* operator new (size_t);
Thus, In the first example, the new operator expects the 'type' and not the size, since it also needs to call the constructor on that type. Hence the first line gives compilation error. (1024 is not a type.)
On the second line, you are explicitly calling the 'operator new'. In other words, what you are doing is only the first step (allocating the memory). The 'operator new' requires size_t which you have provided properly (1024), and hence the code compiles properly.
11. What is the difference between assignment and initialization?
Assignment changes the value of the object that has already been constructed.
Assignment operation can be executed many times;
Initialization constructs a new object and gives it a value at the same time.
Initialization operation can only be executed once.
For example, you can initialize a const type object, but you can not do assignment on it.
12. What is polymorphism? How does it implemented?
In programming languages, polymorphism means that some code or operations or objects behave differently in different contexts. It is an ability to call different functions by using only one type of function call. Typically, polymorphism in C++ is implemented by using virtual methods.
(一篇简短又易懂的文章形像的介绍了如何用虚函数实现了多态http://www.cublog.cn/u/5391/showart_203729.html )
13. What is encapsulation?
Encapsulation is the process to hide the implementation details of the object and the only thing that remains externally visible is the interface of the object.
14. Copy constructor
The copy constructor lets you create a new object from an existing one by initialization. A copy constructor of a class A is a non-template constructor in which the first parameter is of type A& , const A& , volatile A& , or const volatile A& , and the rest of its parameters (if there are any) have default values.
15. Difference between copy constructor and assignment .
A copy constructor is used to initialize a newly declared variable from an existing variable. This makes a deep copy like assignment, but it is somewhat simpler:
16. What’s the difference between pointer and reference?
Pointer *
1) Its not necessary to initialize the pointer at the time of declaration. Like
A friend of a class is X a function or class that is not a member of X, but is granted the same access to X as X's members. Functions declared with "friend" label in a class member list are called "Friend Functions"; Classes declared with the "friend" label in the member list of another class are called "Friend Classes" of that class.
18. What’s the binary search tree? (data structure)
A binary tree where every node's left subtree has keys less than the node's key, and every right subtree has keys greater than the node's key.
19. What’s the stack?
The stack is a place in the computer memory where all the variables that are declared and initialized before runtime are stored.
20. What’s LIFO (Last In First Out)?
In a LIFO structured linear list, elements can be added or taken off from only one end, called the "top ".
21. Given a stack, and 5 variables, require you put the 5 variables into the stack. How would you test it before putting them in?
Destructors are usually used to deallocate memory and do other cleanup for a class object and its class members when the object is destroyed. A destructor is called for a class object when that object passes out of scope or is explicitly deleted. A destructor is a member function with the same name as its class prefixed by a ~ (tilde).
(A constructor can be declared as virtual or static; but a destructor can be declared virtual or pure virtual)
30. What is copy constructor? When it is called?
A copy constructor is called whenever a new variable is created from an object. This happens in the following cases (but not in assignment).
31. Overloading and overriding difference
Overriding is the example of run-time polymorphism and Overloading is the example of compile-time polymorphism.
Overriding
■The return type must exactly match that of the overridden method.
■The access level must not be more restrictive than that of the overridden method.
■The access level can be less restrictive than that of the overridden method.
■The overriding method must not throw new or broader checked exceptions than those declared by the overridden method.
■The overriding method can throw narrower or fewer exceptions. Just because an overridden method “takes risks” doesn’t mean that the overriding subclass’ exception takes the same risks. Bottom line: An overriding method doesn’t have to declare any exceptions that it will never throw, regardless of what the overridden method declares.
■You cannot override a method marked final.
■If a method can’t be inherited, you cannot override it.
Overloaded method
■Overloaded methods must change the argument list.
■Overloaded methods can change the return type.
■Overloaded methods can change the access modifier.
■Overloaded methods can declare new or broader checked exceptions.
■A method can be overloaded in the same class or in a subclass.
32. what is recurcive function? Implement one recurcive funcition.
Recursive function is a function which contains a call to itself.
For example: find n!
int *a;
point to 20 intergers;
int (*a)[20];
point to 20 pointers which point to interger
int *a[20];
34. What’s virtual destructor?
If an object (with a non-virtual destructor) is destroyed explicitly by applying the delete operator to a base-class pointer to the object, the base-class destructor function (matching the pointer type) is called on the object.
There is a simple solution to this problem: declare a virtual base-class destructor . This makes all derived-class destructors virtual even though they don't have the same name as the base-class destructor. Now, if the object in the hierarchy is destroyed explicitly by applying the delete operator to a base-class pointer to a derived-class object, the destructor for the appropriate class is called.
( )
35. How is the source file compiled to executable(from source file -> binary file)?
A compiler is likely to perform many or all of the following operations: => => => semantic analysis=> => .
For GCC, the sequence of commands executed by a single invocation of GCC consists of the following stages:
36. After the source file is compiled to binary file, how is the binary file orgnized and stored?
37. What is overloading? How does the computer know which function is according to which implementation since they have the same name?
The operator keyword declares a function specifying what operator-symbol means when applied to instances of a class. This gives the operator more than one meaning, or "overloads" it. The compiler distinguishes between the different meanings of an operator by examining the types of its operands .
38. Memory leakage:
A memory leak or leakage in computer science is a particular type of memory consumption by a computer program where the program is unable to release memory it has acquired.
How you ever met memory leakage program, is it cause severe problem?
For firefox, the memory leakage is not a bug, it it a feature!
How did you find the leakage?
Have you ever used any software to detect the memory leakage?
https://developer.mozilla.org/en/Debugging_memory_leaks
39. c++ file in Linux: which compiler do you use?
GCC
40. Given a file, tell me the steps of reading the file.
41. What is “IS” and “Has” in C++? What’s the difference?
Is-a is a relationship where one class D is a subclass of another class B (and so B is a superclass of D );
Has-a is a relationship where one object "belongs" to (is a part or member of) another object. In simple words, has-a relationship in an object is called member field of an object.
Is-a relationship constitutes a hierachy of subtyping/subtype polymorphism; Multiple has-a relationships will combine to form a possessive hierarchy.
(参考http://blog.chinaunix.net/u2/85848/showart_1962718.html )
42. the disadvantage of using stored procedures with parameters.
43. when inserting a record into a table, how can you let the relatived tables change accordingly?
44. What is the difference between declaration and definition?
The declaration tells the compiler that at some later point we plan to present the definition of this declaration.
The definition contains the actual implementation. (contains body)
Cisco 试题:What will print out?
Answer:empty string.
What will be printed as the result of the operation below:
Answer : 5794
What will be printed as the result of the operation below:
Answer: 5,20,1
What will be printed as the result of the operation below:
Answer: 10, 5
10, 5
What will be printed as the result of the operation below:
Answer:Cisco Systems
isco systems
What will be printed as the result of the operation below:
Answer: Cisco
What will be printed as the result of the operation below:
Answer: Ciscosystems
The following variable is available in file1.c, who can access it?:
Answer: all the functions in the file1.c can access the variable.
What will be the result of the following code?
Answer: This will not go into the loop as TRUE is defined as 0.
What will be printed as the result of the operation below:
Answer: 12 , 13 , 13
What will be printed as the result of the operation below:
Answer: 11, 16
What will be printed as the result of the operation below:
Answer: Two lines with “Cisco Systems” will be printed.
====
Quotes :
A difference between a destructor (of course also the constructor) and other member functions is that, if a regular member function has a body at the derived class, only the version at Derived class gets executed. Whereas in case of destructors, both derived as well as base class versions get executed.
22. How would you test your own program?
23. Tell me the first three of your most familiar technical skills.
24. What’s the persentage of back-in, middle tier, and front-in development?
25. What do you think a good code is?
26. How do you keep you with the latest technologies?
27. distance vector routing protocol
It's one of the two major classes of routing protocols used in packet-switched networks for computer communications , the other major class being the link-state protocol . A distance-vector routing protocol uses the Bellman-Ford algorithm to calculate paths.
Ignoring speed of development for a moment, is the best code software that:
28. c and c++ difference
OOP concepts
29. Explain constructor and destructor
A constructor is a member function with the same name as its class. Constructors are used to create, and can initialize, objects of their class type.
转载自:http://blog.csdn.net/Lixinag/archive/2010/04/01/5441417.aspx