C++ Viva Questions
C++ Viva Question
1. What is difference between compiler & interpreter ?
Ans. Interpreters read through source code and translate a program, turning the programmer's code or program instruction , directly into actions compilers translate source code into on executable , program that can be run at a later time.
2. What does the linker do?
Ans. The linker's job is to tie together your compiled code with the libraries supplied by your compiler vendor and the other source . The linker lets you build your program in pieces and then link together pieces into one big program.
3. What are the steps in development cycle?
Ans. Edit source code → compile →link → test → repeat
4. What is the difference between the compiler and a preprocessor?
Ans. Each time you run your compiler, the preprocessor runs first it react through your source code and includes files you've asked for, and performs other housekeeping chores. The preprocessor is discussed in detail on day is "object oriented Analysis and design"
5. Can Comments be nested?
Ans. Yes , C++ style comments can be nested within c-style comments. You can, in fact, nest c-style comments within c++ style comments as long as you remember that C++ style comments end at the end of the line.
6. Why is the function main() Special?
Ans. main() is called automatically, each time your program is executed.
7. Can comments be longer than one?
Ans. C-style comments can. If you want to extend C++ style comments to a second line, you must put another set of double slashes( //).
8. Do the names of parameters have to agree in the prototype, definition and call to the function?
Ans. No, All parameter are identified by position, not same.
9. If a function doesn't return value, how do you declare a function?
Ans. Declare the function to return void.
10. If you don't declare return , what type of return value is assume?
Ans. Any function that does not explicitly declare a return type return type returns int.
11. What is a local variable?
Ans. A local variable is a variable passed into or declared within a block. typically a function .It is visible only within the block.
12. What is a scope?
Ans. Scope refers to the visibility and lifetime of local and global variables. Scope is usually established by a set of braces.
13.What is Recursion?
Ans. Recursion generally refers to the ability of a function to call itself.
14. When should you use global variables?
Ans. Global variables are typically used when many function. need access to same data. Global variables are very rare in C++; once you know how to create static class , variable you will almost never create global variables
15. What is function overloading ?
Ans. Function overloading is the ability to write more than one function when some name, distinguish by the number or type of the parameter.
16. What do you mean by polymorphism?
Ans. Polymorphism is the ability to treat many objects or differing but related types without regards to their difference in C++ polymorphism is the accomplished by using class derivation and virtual function.
17. Is the declaration of the class its interface or its implements?
Ans. The declaration of a class is its interface ,it tells , clients of the class how to interest interact with the class . The implementation of the class is the set of member function stored usually in a related CPP file.
18. What is difference between public & private data member?
Ans. Public data members can be accessed by clients of the class . private data members can be accessed only by member function of the private.
19. Can member function be private?
Ans. Yes , both member function and member data can be private.
20. Can member data be public ?
Ans. Although , member data can be public , it is good programming practice to make it private and provide public accessor function to the data.
21. What is difference between the indirection operator and the address of a parameter?
Ans. The indirection operator returns the value at the address stored in a pointer. The address of operator(&) returns the memory address of the variables.
22. What is difference between reference & pointer?
Ans. A reference is an alias, and a pointer is a variable that holds an address . references cannot be null and cannot be assigned to.
23. When must you use a pointer rather than a reference?
Ans. When you may need to reassign what is pointed to, or when pointer may be null.
24. What does new return if there is insufficient memory to make your new object?
Ans. A null pointer.
25.What is a constant references?
Ans. This is a shorthand way of saying "a reference to a constant object".
26. What is difference between passing by reference & passing a reference ?
Ans. Passing by reference means not making a local copy. It can be accomplished by passing a reference or by passing a pointer.
27. When you overload member function in what ways must they differ?
Ans. Overloaded member function are functions in a class that share a name but differ in the number or type of their parameters.
28. What is difference between declaration & definition ?
Ans. A definition sets aside a memory , but a declaration does not. Almost all declarations are definition , the major exception are class declaration, function prototype, and typedef statements.
29.When is the copy constructor called?
Ans. Whenever a temporary copy of an object is created. this happens every time an object is passed by volume.
30.When is the destructor called?
Ans. The destructor is called each time an object is destroyed, either because it goes out of scope of because you call delete on a pointer painting.
Comments
Post a Comment