Thursday, May 7, 2009

Short cut keys in Visual Studio

General
Ctrl-X orShift-Delete
Cuts the currently selected item to the clipboard
Ctrl-C orCtrl-Insert
Copies the currently selected item to the clipboard
Ctrl-V orShift-Insert
Pastes the item in the clipboard at the cursor
Ctrl-Z orAlt-Backspace
Undo previous editing action
Ctrl-Y orCtrl-Shift-Z
Redo the previous undo action
Ctrl-Shift-V orCtrl-Shift-Insert
Pastes an item from the clipboard ring tab of the Toolbox at the cursor in the file and automatically selects the pasted item. Cycle through the items on the clipboard by pressing the shortcut keys repeatedly
Esc
Closes a menu or dialog, cancels an operation in progress, or places focus in the current document window
Ctrl-S
Saves the selected files in the current project (usually the file that is being edited)
Ctrl-Shift-S
Saves all documents and projects
Ctrl-P
Displays the Print dialog
F7
Switches from the design view to the code view in the editor
Shift-F7
Switches from the code view to the design view in the editor
F8
Moves the cursor to the next item, for example in the TaskList window or Find Results window
Shift-F8
Moves the cursor to the previous item, for example in the TaskList window or Find Results window
Shift-F12
Finds a reference to the selected item or the item under the cursor
Ctrl-Shift-G
Opens the file whose name is under the cursor or is currently selected
Ctrl-/
Switches focus to the Find/Command box on the Standard toolbar
Ctrl-Shift-F12
Moves to the next task in the TaskList window
Ctrl-Shift-8
Moves backward in the browse history. Available in the object browser or Class View window
Alt-Left Arrow
Go back in the web browser history
Alt-Right Arrow
Go forward in the web browser history
return to top
Text navigation
Shortcut
Description
Left Arrow
Moves the cursor one character to the left
Right Arrow
Moves the cursor one character to the right
Down Arrow
Moves the cursor down one line
Up Arrow
Moves the cursor up one line
Page Down
Scrolls down one screen in the editor window
Page Up
Scrolls up one screen in the editor window
End
Moves the cursor to the end of the current line
Home
Moves the cursor to the beginning of the line. If you press Home when the cursor is already at the start of the line, it will toggle the cursor between the first non-whitespace character and the real start of the line
Ctrl-End
Moves the cursor to the end of the document
Ctrl-Home
Moves the cursor to the start of the document
Ctrl-G
Displays the Go to Line dialog. If the debugger is running, the dialog also lets you specify addresses or function names to go to
Ctrl-]
Moves the cursor to the matching brace in the document. If the cursor is on an opening brace, this will move to the corresponding closing brace and vice versa
Ctrl-K, Ctrl-N
Moves to the next bookmark in the document
Ctrl-K, Ctrl-P
Moves to the previous bookmark
Ctrl-K, Ctrl-I
Displays Quick Info, based on the current language
Ctrl-Down Arrow
Scrolls text down one line but does not move the cursor. This is useful for scrolling more text into view without losing your place. Available only in text editors
Ctrl-Up Arrow
Scrolls text up one line but does not move the cursor. Available only in text editors
Ctrl-Right Arrow
Moves the cursor one word to the right
Ctrl-Left Arrow
Moves the cursor one word to the left
Ctrl-Shift-1
Navigates to the next definition, declaration, or reference of an item. Available in the object browser and Class View window. Also available in source editing windows if you have already used the Edit.GoToReference (Shift-F12) shortcut
Ctrl-Shift-2
Navigates to the previous definition, declaration, or reference of an item
Text manipulation
Enter
Inserts a new line
Delete
Deletes one character to the right of the cursor
Insert
Toggles between insert and overtype insertion modes
Tab
Indents the currently selected line or lines by one tab stop. If there is no selection, this inserts a tab stop
Shift-Tab
Moves current line or selected lines one tab stop to the left
Backspace orShift-Backspace
Deletes one character to the left of the cursor
Ctrl-K, Ctrl-C
Marks the current line or selected lines of code as a comment, using the correct comment syntax for the programming language
Ctrl-K, Ctrl-U
Removes the comment syntax from the current line or currently selected lines of code
Ctrl-T or Shift-Enter
Swaps the characters on either side of the cursor. (For example, ACBD becomes ABCD.) Available only in text editors
Ctrl-K, Ctrl-L
Removes all unnamed bookmarks in the current document
Ctrl-M, Ctrl-O
Automatically determines logical boundaries for creating regions in code, such as procedures, and then hides them. This collapses all such regions in the current document
Alt-Right Arrow or Ctrl-Spacebar
Displays statement completion based on the current language or autocompletes word if existing text unambiguously identifies a single symbol
Ctrl-K, Ctrl-\
Removes horizontal whitespace in the selection or deletes whitespace adjacent to the cursor if there is no selection
Ctrl-K, Ctrl-F
Applies the indenting and space formatting for the language as specified on the Formatting pane of the language in the Text Editor section of the Options dialog to the selected text.
Ctrl-L
Cuts all selected lines or the current line if nothing has been selected to the clipboard
Ctrl-Shift-L
Deletes all selected lines or the current line if no selection has been made
Ctrl-Enter
Inserts a blank line above the cursor
Ctrl-Shift-Enter
Inserts a blank line below the cursor
Shift-Alt-T
Moves the line containing the cursor below the next line
Ctrl-J
Lists members for statement completion when editing code
Ctrl-U
Changes the selected text to lowercase characters
Ctrl-Shift-U
Changes the selected text to uppercase characters
Ctrl-Shift-Spacebar
Displays a tooltip that contains information for the current parameter, based on the current language
Ctrl-M, Ctrl-U
Removes the outlining information for the currently selected region
Ctrl-M, Ctrl-P
Removes all outlining information from the entire document
Ctrl-R, Ctrl-P
Swaps the anchor and endpoint of the current selection
Ctrl-M, Ctrl-L
Toggles all previously marked hidden text sections between hidden and display states
Ctrl-K, Ctrl-K
Sets or removes a bookmark at the current line
Ctrl-M, Ctrl-M
Toggles the currently selected hidden text section or the section containing the cursor if there is no selection between the hidden and display states
Ctrl-K, Ctrl-H
Sets or removes a shortcut in the tasklist to the current line
Ctrl-R, Ctrl-R
Enables or disables word wrap in an editor
Ctrl-R, Ctrl-W
Shows or hides spaces and tab marks
Ctrl-Delete
Deletes the word to the right of the cursor
Ctrl-Backspace
Deletes the word to the left of the cursor
Ctrl-Shift-T
Transposes the two words that follow the cursor. (For example, End Sub would be changed to read Sub End.)

Text selection

Shift-Left Arrow
Moves the cursor to the left one character, extending the selection
Shift-Alt-Left Arrow
Moves the cursor to the left one character, extending the column selection
Shift-Right Arrow
Moves the cursor to the right one character, extending the selection
Shift-Alt-Right Arrow
Moves the cursor to the right one character, extending the column selection
Ctrl-Shift-End
Moves the cursor to the end of the document, extending the selection
Ctrl-Shift-Home
Moves the cursor to the start of the document, extending the selection
Ctrl-Shift-]
Moves the cursor to the next brace, extending the selection
Shift-Down Arrow
Moves the cursor down one line, extending the selection
Shift-Alt-Down Arrow
Moves the cursor down one line, extending the column selection
Shift-End
Moves the cursor to the end of the current line, extending the selection
Shift-Alt-End
Moves the cursor to the end of the line, extending the column selection
Shift-Home
Moves the cursor to the start of the line, extending the selection
Shift-Alt-Home
Moves the cursor to the start of the line, extending the column selection
Shift-Up Arrow
Moves the cursor up one line, extending the selection
Shift-Alt-Up Arrow
Moves the cursor up one line, extending the column selection
Shift-Page Down
Extends selection down one page
Shift-Page Up
Extends selection up one page
Ctrl-A
Selects everything in the current document
Ctrl-W
Selects the word containing the cursor or the word to the right of the cursor
Ctrl-=
Selects from the current location in the editor back to the previous location in the navigation history
Ctrl-Shift-Page Down
Moves the cursor to the last line in view, extending the selection
Ctrl-Shift-Page Up
Moves the cursor to the top of the current window, extending the selection
Ctrl-Shift-Alt-Right Arrow
Moves the cursor to the right one word, extending the column selection
Ctrl-Shift-Left Arrow
Moves the cursor one word to the left, extending the selection
Ctrl-Shift-Alt-Left Arrow
Moves the cursor to the left one word, extending the column selection

Project related

Ctrl-Shift-B
Builds the solution
Ctrl-N
Displays the New File dialog. Note: files created this way are not associated with a project. Use Ctrl-Shift-A to add a new file in a project
Ctrl-Shift-N
Displays the New Project dialog
Ctrl-O
Displays the Open File dialog
Ctrl-Shift-O
Displays the Open Project dialog
Shift-Alt-A
Displays the Add Existing Item dialog
Ctrl-Shift-A
Displays the Add New Item dialog
Ctrl-Alt-Insert
Allows you to override base class methods in a derived class when an overridable method is highlighted in the Class View pane

Window manipulation

Shift-Alt-Enter
Toggles full screen mode
Ctrl-+
Goes back to the previous location in the navigation history. (For example, if you press Ctrl-Home to go to the start of a document, this shortcut will take the cursor back to wherever it was before you pressed Ctrl-Home.)
Ctrl-Shift-+
Moves forward in the navigation history. This is effectively an undo for the View.NavigateBackward operation
Ctrl-F4
Closes the current MDI child window
Shift-Esc
Closes the current tool window
Ctrl-F2
Moves the cursor to the navigation bar at the top of a code view
Ctrl-Tab
Cycles through the MDI child windows one window at a time
Ctrl-F6,Ctrl-Shift-Tab
Moves to the previous MDI child window
Alt-F6,Ctrl-Shift-F6
Moves to the next tool window
Shift-Alt-F6
Moves to the previously selected window
F6
Moves to the next pane of a split pane view of a single document
Shift-F6
Moves to the previous pane of a document in split pane view
Ctrl-Pagedown
Moves to the next tab in the document or window (e.g., you can use this to switch the HTML editor from its design view to its HTML view
Ctrl-PageUp
Moves to the previous tab in the document or window
Control editor (designer)

Ctrl-Down Arrow
Moves the selected control down in increments of one on the design surface
Down Arrow
Moves the selected control down to the next grid position on the design surface
Ctrl-Left Arrow
Moves the control to the left in increments of one on the design surface
Left Arrow
Moves the control to the left to the next grid position on the design surface
Ctrl-Right Arrow
Moves the control to the right in increments of one on the design surface
Right Arrow
Moves the control to the right into the next grid position on the design surface
Ctrl-Up Arrow
Moves the control up in increments of one on the design surface
Up Arrow
Moves the control up into the next grid position on the design surface
Tab
Moves to the next control in the tab order
Shift-Tab
Moves to the previous control in the tab order
Ctrl-Shift-Down Arrow
Increases the height of the control in increments of one on the design surface
Shift-Down Arrow
Increases the height of the control to the next grid position on the design surface
Ctrl-Shift-Left Arrow
Reduces the width of the control in increments of one on the design surface
Shift-Left Arrow
Reduces the width of the control to the next grid position on the design surface
Ctrl-Shift-Right Arrow
Increases the width of the control in increments of one on the design surface
Shift-Left Arrow
Increases the width of the control to the next grid position on the design surface
Ctrl-Shift-Up Arrow
Decreases the height of the control in increments of one on the design surface
Shift-Up Arrow
Decreases the height of the control to the next grid position on the design surface

Search and replace
Ctrl-F
Displays the Find dialog
Ctrl-Shift-F
Displays the Find in Files dialog
F3
Finds the next occurrence of the previous search text
Ctrl-F3
Finds the next occurrence of the currently selected text or the word under the cursor if there is no selection
Shift-F3
Finds the previous occurrence of the search text
Ctrl-Shift-F3
Finds the previous occurrence of the currently selected text or the word under the cursor
Ctrl-D
Places the cursor in the Find/Command line on the Standard toolbar
Alt-F3, H
Selects or clears the Search Hidden Text option for the Find dialog
Ctrl-I
Starts an incremental search—after pressing Ctrl-I, you can type in text, and for each letter you type, VS.NET will find the first occurrence of the sequence of letters you have typed so far. This is a very convenient facility, as it lets you find text by typing in exactly as many characters as are required to locate the text and no more. If you press Ctrl-I a second time without typing any characters, it recalls the previous pattern. If you press it a third time or you press it when an incremental search has already found a match, VS.NET searches for the next occurrence.
Alt-F3, C
Selects or clears the Match Case option for Find and Replace operations
Alt-F3, R
Selects or clears the Regular Expression option so that special characters can be used in Find and Replace operations
Ctrl-H
Displays the Replace dialog
Ctrl-Shift-H
Displays the Replace in Files dialog
Ctrl-Shift-I
Performs an incremental search in reverse direction
Alt-F3, S
Halts the current Find in Files operation
Alt-F3, B
Selects or clears the Search Up option for Find and Replace operations
Alt-F3, W
Selects or clears the Match Whole Word option for Find and Replace operations
Alt-F3, P
Selects or clears the Wildcard option for Find and Replace operations

Help

Ctrl-Alt-F1
Displays the Contents window for the documentation
Ctrl-F1
Displays the Dynamic Help window, which displays different topics depending on what items currently have focus. If the focus is in a source window, the Dynamic Help window will display help topics that are relevant to the text under the cursor
F1
Displays a topic from Help that corresponds to the part of the user interface that currently has the focus. If the focus is in a source window, Help will try to display a topic relevant to the text under the cursor
Ctrl-Alt-F2
Displays the Help Index window
Shift-Alt-F2
Displays the Index Results window, which lists the topics that contain the keyword selected in the Index window
Alt-Down Arrow
Displays the next topic in the table of contents. Available only in the Help browser window
Alt-Up Arrow
Displays the previous topic in the table of contents. Available only in the Help browser window
Ctrl-Alt-F3
Displays the Search window, which allows you to search for words or phrases in the documentation
Shift-Alt-F3
Displays the Search Results window, which displays a list of topics that contain the string searched for from the Search window.
Shift-F1
Displays a topic from Help that corresponds to the user interface item that has the focus

Debugging

Ctrl-Alt-V, A
Displays the Auto window to view the values of variables currently in the scope of the current line of execution within the current procedure
Ctrl-Alt-Break
Temporarily stops execution of all processes in a debugging session. Available only in run mode
Ctrl-Alt-B
Displays the Breakpoints dialog, where you can add and modify breakpoints
Ctrl-Alt-C
Displays the Call Stack window to display a list of all active procedures or stack frames for the current thread of execution. Available only in break mode
Ctrl-Shift-F9
Clears all of the breakpoints in the project
Ctrl-Alt-D
Displays the Disassembly window
Ctrl-F9
Enables or disables the breakpoint on the current line of code. The line must already have a breakpoint for this to work
Ctrl-Alt-E
Displays the Exceptions dialog
Ctrl-Alt-I
Displays the Immediate window, where you can evaluate expressions and execute individual commands
Ctrl-Alt-V, L
Displays the Locals window to view the variables and their values for the currently selected procedure in the stack frame
Ctrl-Alt-M, 1
Displays the Memory 1 window to view memory in the process being debugged. This is particularly useful when you do not have debugging symbols available for the code you are looking at. It is also helpful for looking at large buffers, strings, and other data that does not display clearly in the Watch or Variables window
Ctrl-Alt-M, 2
Displays the Memory 2 window
Ctrl-Alt-M, 3
Displays the Memory 3 window
Ctrl-Alt-M, 4
Displays the Memory 4 window
Ctrl-Alt-U
Displays the Modules window, which allows you to view the .dll or .exe files loaded by the program. In multiprocess debugging, you can right-click and select Show Modules for all programs
Ctrl-B
Opens the New Breakpoint dialog
Ctrl-Alt-Q
Displays the Quick Watch dialog with the current value of the selected expression. Available only in break mode. Use this command to check the current value of a variable, property, or other expression for which you have not defined a watch expression
Ctrl-Alt-G
Displays the Registers window, which displays CPU register contents
Ctrl-Shift-F5
Terminates the current debugging session, rebuilds if necessary, and then starts a new debugging session. Available in break and run modes
Ctrl-Alt-N
Displays the Running Documents window that displays the set of HTML documents that you are in the process of debugging. Available in break and run modes
Ctrl-F10
Starts or resumes execution of your code and then halts execution when it reaches the selected statement. This starts the debugger if it is not already running
Ctrl-Shift-F10
Sets the execution point to the line of code you choose
Alt-NUM *
Highlights the next statement to be executed
F5
If not currently debugging, this runs the startup project or projects and attaches the debugger. If in break mode, this allows execution to continue (i.e., it returns to run mode).
Ctrl-F5
Runs the code without invoking the debugger. For console applications, this also arranges for the console window to stay open with a "Press any key to continue" prompt when the program finishes
F11
Executes code one statement at a time, tracing execution into function calls
Shift-F11
Executes the remaining lines of a function in which the current execution point lies
F10
Executes the next line of code but does not step into any function calls
Shift-F5
Available in break and run modes, this terminates the debugging session
Ctrl-Alt-V, T
Displays the This window, which allows you to view the data members of the object associated with the current method
Ctrl-Alt-H
Displays the Threads window to view all of the threads for the current process
F9
Sets or removes a breakpoint at the current line
Ctrl-F11
Displays the disassembly information for the current source file. Available only in break mode
Ctrl-Alt-W, 1
Displays the Watch 1 window to view the values of variables or watch expressions
Ctrl-Alt-W, 2
Displays the Watch 2 window
Ctrl-Alt-W, 3
Displays the Watch 3 window
Ctrl-Alt-W, 4
Displays the Watch 4 window
Ctrl-Alt-P
Displays the Processes dialog, which allows you to attach or detach the debugger to one or more running processes

Object browser

Alt-F12
Displays the Find Symbol dialog
Ctrl-F12
Displays the declaration of the selected symbol in the code
F12
Displays the definition for the selected symbol in code
Ctrl-Alt-F12
Displays the Find Symbol Results window
Ctrl-Alt-J
Displays the Object Browser to view the classes, properties, methods, events, and constants defined either in your project or by components and type libraries referenced by your project
Alt-+
Moves back to the previously selected object in the selection history of the object browser
Shift-Alt-+
Moves forward to the next object in the selection history of the object browser

Tool window

Ctrl-Shift-M
Toggles the Command window into or out of a mode allowing text within the window to be selected
Ctrl-Shift-C
Displays the Class View window
Ctrl-Alt-A
Displays the Command window, which allows you to type commands that manipulate the IDE
Ctrl-Alt-T
Displays the Document Outline window to view the flat or hierarchical outline of the current document
Ctrl-Alt-F
Displays the Favorites window, which lists shortcuts to web pages
Ctrl-Alt-O
Displays the Output window to view status messages at runtime
F4
Displays the Properties window, which lists the design-time properties and events for the currently selected item
Shift-F4
Displays the property pages for the item currently selected. (For example, use this to show a project's settings.)
Ctrl-Shift-E
Displays the Resource View window
Ctrl-Alt-S
Displays the Server Explorer window, which allows you to view and manipulate database servers, event logs, message queues, web services, and many other operating system services
Ctrl-Alt-R
Displays the web browser window, which allows you to view pages on the Internet
Ctrl-Alt-L
Displays the Solution Explorer, which lists the projects and files in the current solution
Ctrl-Alt-K
Displays the TaskList window, which displays tasks, comments, shortcuts, warnings, and error messages
Ctrl-Alt-X
Displays the Toolbox, which contains controls and other items that can be dragged into editor and designer windows

Html editor (Design View)

Ctrl-B
Toggles the selected text between bold and normal
Ctrl-Shift-T
Decreases the selected paragraph by one indent unit
Ctrl-T
Indents the selected paragraph by one indent unit
Ctrl-I
Toggles the selected text between italic and normal
Ctrl-Shift-K
Prevents an absolutely positioned element from being inadvertently moved. If the element is already locked, this unlocks it
Ctrl-G
Toggles the grid
Ctrl-Shift-G
Specifies that elements be aligned using an invisible grid. You can set grid spacing on the Design pane of HTML designer options in the Options dialog, and the grid will be changed the next time you open a document
Ctrl-U
Toggles the selected text between underlined and normal
Ctrl-Shift-L
Displays the Bookmark dialog
Ctrl-J
Inserts
in the current HTML document
Ctrl-L
When text is selected, displays the Hyperlink dialog
Ctrl-Shift-W
Displays the Insert Image dialog
Ctrl-Alt-Up Arrow
Adds one row above the current row in the table
Ctrl-Alt-Down Arrow
Adds one row below the current row in the table
Ctrl-Alt-Left Arrow
Adds one column to the left of the current column in the table
Ctrl-Alt-Right Arrow
Adds one column to the right of the current column in the table
Ctrl-Shift-Q
Toggles display of marker icons for HTML elements that do not have a visual representation, such as comments, scripts, and anchors for absolutely positioned elements
Ctrl-Page Down
Switches from design view to HTML view and vice versa
Ctrl-Q
Displays a 1-pixel border around HTML elements that support a BORDER attribute and have it set to zero, such as tables, table cells, and divisions

Macro
Alt-F8
Displays the Macro Explorer window, which lists all available macros
Alt-F11
Launches the macros IDE
Ctrl-Shift-R
Places the environment in macro record mode or completes recording if already in record mode
Ctrl-Shift-P
Plays back a recorded macro

Wednesday, May 6, 2009

C++ Interview Question and Answers


1. ) What is encapsulation??
Containing and hiding information about an object, such as internal data structures and code. Encapsulation isolates the internal complexity of an object's operation from the rest of the application. For example, a client component asking for net revenue from a business object need not know the data's origin.
2.)What is inheritance?
Inheritance allows one class to reuse the state and behavior of another class. The derived class inherits the properties and method implementations of the base class and extends it by overriding methods and adding additional properties and methods.
3.) What is Polymorphism??
Polymorphism allows a client to treat different objects in the same way even if they were created from different classes and exhibit different behaviors.You can use implementation inheritance to achieve polymorphism in languages such as C++ and Java.Base class object's pointer can invoke methods in derived class objects.You can also achieve polymorphism in C++ by function overloading and operator overloading.
4.) What is constructor or ctor?
Constructor creates an object and initializes it. It also creates vtable for virtual functions. It is different from other methods in a class.What is destructor?Destructor usually deletes any extra resources allocated by the object.
5.) What is default constructor?
Constructor with no arguments or all the arguments has default values.
6.)What is copy constructor?
Constructor which initializes the it's object member variables ( by shallow copying) with another object of the same class. If you don't implement one in your class then compiler implements one for you.for example:Boo Obj1(10); // calling Boo constructorBoo Obj2(Obj1); // calling boo copy constructorBoo Obj2 = Obj1;// calling boo copy constructor
7.) When are copy constructors called?
Copy constructors are called in following cases:a) when a function returns an object of that class by valueb) when the object of that class is passed by value as an argument to a functionc) when you construct an object based on another object of the same classd) When compiler generates a temporary object
8.) What is assignment operator?
Default assignment operator handles assigning one object to another of the same class. Member to member copy (shallow copy)What are all the implicit member functions of the class? Or what are all the functions which compiler implements for us if we don't define one.??default ctorcopy ctorassignment operatordefault destructoraddress operator
9.) What is conversion constructor?
Constructor with a single argument makes that constructor as conversion ctor and it can be used for type conversion.for example:class Boo{public:Boo( int i );};Boo BooObject = 10 ; // assigning int 10 Boo object
10.) What is conversion operator?
class can have a public method for specific data type conversions.for example:class Boo{double value;public:Boo(int i )operator double(){return value;}};Boo BooObject;double i = BooObject; // assigning object to variable i of type double. now conversion operator gets called to assign the value.
11.) What is diff between malloc()/free() and new/delete?
malloc allocates memory for object in heap but doesn't invoke object's constructor to initiallize the object.
new allocates memory and also invokes constructor to initialize the object.
malloc() and free() do not support object semanticsDoes not construct and destruct objectsstring * ptr = (string *)(malloc (sizeof(string)))Are not safeDoes not calculate the size of the objects that it constructReturns a pointer to voidint *p = (int *) (malloc(sizeof(int)));int *p = new int;Are not extensiblenew and delete can be overloaded in a class
"delete" first calls the object's termination routine (i.e. its destructor) and then releases the space the object occupied on the heap memory. If an array of objects was created using new, then delete must be told that it is dealing with an array by preceding the name with an empty []:-
Int_t *my_ints = new Int_t[10];
...
delete []my_ints;
12.) What is the diff between "new" and "operator new" ?
"operator new" works like malloc.
What is difference between template and macro??
There is no way for the compiler to verify that the macro parameters are of compatible types. The macro is expanded without any special type checking.
If macro parameter has a postincremented variable ( like c++ ), the increment is performed two times.
Because macros are expanded by the preprocessor, compiler error messages will refer to the expanded macro, rather than the macro definition itself. Also, the macro will show up in expanded form during debugging.
for example:
Macro:
#define min(i, j) (i <>
template:templateT min (T i, T j){return i <>
13.) What are C++ storage classes?
autoregisterstaticextern
auto: the default. Variables are automatically created and initialized when they are defined and are destroyed at the end of the block containing their definition. They are not visible outside that block
register: a type of auto variable. a suggestion to the compiler to use a CPU register for performance
static: a variable that is known only in the function that contains its definition but is never destroyed and retains its value between calls to that function. It exists from the time the program begins execution
extern: a static variable whose definition and placement is determined when all object and library modules are combined (linked) to form the executable code file. It can be visible outside the file where it is defined.
14.) What are storage qualifiers in C++ ?
They are..
constvolatilemutable
Const keyword indicates that memory once initialized, should not be altered by a program.
volatile keyword indicates that the value in the memory location can be altered even though nothing in the programcode modifies the contents. for example if you have a pointer to hardware location that contains the time, where hardware changes the value of this pointer variable and not the program. The intent of this keyword to improve the optimization ability of the compiler.
mutable keyword indicates that particular member of a structure or class can be altered even if a particular structure variable, class, or class member function is constant.
struct data{char name[80];mutable double salary;}
const data MyStruct = { "Hello World", 1000 }; //initlized by complier
strcpy ( MyStruct.name, "Hello World"); // compiler errorMyStruct.salaray = 2000 ; // complier is happy allowed
15.) What is reference ??
reference is a name that acts as an alias, or alternative name, for a previously defined variable or an object.
prepending variable with "&" symbol makes it as reference.
for example:
int a;int &b = a;
16.) What is passing by reference?
Method of passing arguments to a function which takes parameter of type reference.
for example:
void swap( int & x, int &amp;amp;amp; y ){int temp = x;x = y;y = temp;}
int a=2, b=3;
swap( a, b );
Basically, inside the function there won't be any copy of the arguments "x" and "y" instead they refer to original variables a and b. so no extra memory needed to pass arguments and it is more efficient.
17.) When do use "const" reference arguments in function?
a) Using const protects you against programming errors that inadvertently alter data.b) Using const allows function to process both const and non-const actual arguments, while a function without const in the prototype can only accept non constant arguments.c) Using a const reference allows the function to generate and use a temporary variable appropriately.
18.) When are temporary variables created by C++ compiler?
Provided that function parameter is a "const reference", compiler generates temporary variable in following 2 ways.
a) The actual argument is the correct type, but it isn't Lvalue
double Cube(const double & num){num = num * num * num;return num;
}
double temp = 2.0;double value = cube(3.0 + temp); // argument is a expression and not a Lvalue;
b) The actual argument is of the wrong type, but of a type that can be converted to the correct type
long temp = 3L;double value = cuberoot ( temp); // long to double conversion
19.) What is virtual function?
When derived class overrides the base class method by redefining the same function, then if client wants to access redefined the method from derived class through a pointer from base class object, then you must define this function in base class as virtual function.
class parent{void Show(){cout << "i'm parent" << parent_object_ptr =" new">show() // calls parent->show() i
now we goto virtual world...
class parent{virtual void Show(){cout << "i'm parent" << parent_object_ptr =" new">show() // calls child->show()
20.) What is pure virtual function? or what is abstract class?
When you define only function prototype in a base class without implementation and do the complete implementation in derived class. This base class is called abstract class and client won't able to instantiate an object using this base class.
You can make a pure virtual function or abstract class this way..
class Boo{void foo() = 0;}
Boo MyBoo; // compilation error
21. )What is Memory alignment?
The term alignment primarily means the tendency of an address pointer value to be a multiple of some power of two. So a pointer with two byte alignment has a zero in the least significant bit. And a pointer with four byte alignment has a zero in both the two least significant bits. And so on. More alignment means a longer sequence of zero bits in the lowest bits of a pointer.
22.) What problem does the namespace feature solve?
Multiple providers of libraries might use common global identifiers causing a name collision when an application tries to link with two or more such libraries. The namespace feature surrounds a library's external declarations with a unique namespace that eliminates the potential for those collisions.
namespace [identifier] { namespace-body }
A namespace declaration identifies and assigns a name to a declarative region.The identifier in a namespace declaration must be unique in the declarative region in which it is used. The identifier is the name of the namespace and is used to reference its members.
23.) What is the use of 'using' declaration?
A using declaration makes it possible to use a name from a namespace without the scope operator.
24.) What is an Iterator class?
A class that is used to traverse through the objects maintained by a container class. There are five categories of iterators: input iterators, output iterators, forward iterators, bidirectional iterators, random access. An iterator is an entity that gives access to the contents of a container object without violating encapsulation constraints. Access to the contents is granted on a one-at-a-time basis in order. The order can be storage order (as in lists and queues) or some arbitrary order (as in array indices) or according to some ordering relation (as in an ordered binary tree). The iterator is a construct, which provides an interface that, when called, yields either the next element in the container, or some value denoting the fact that there are no more elements to examine. Iterators hide the details of access to and update of the elements of a container class. Something like a pointer.

25.) What is a dangling pointer?
A dangling pointer arises when you use the address of an object after its lifetime is over. This may occur in situations like returning addresses of the automatic variables from a function or using the address of the memory block after it is freed.
26.) What do you mean by Stack unwinding?
It is a process during exception handling when the destructor is called for all local objects in the stack between the place where the exception was thrown and where it is caught.
27.) What is a container class? What are the types of container classes?
A container class is a class that is used to hold objects in memory or external storage. A container class acts as a generic holder. A container class has a predefined behavior and a well-known interface. A container class is a supporting class whose purpose is to hide the topology used for maintaining the list of objects in memory. When a container class contains a group of mixed objects, the container is called a heterogeneous container; when the container is holding a group of objects that are all the same, the container is called a homogeneous container.
What is inline function??
The __inline keyword tells the compiler to substitute the code within the function definition for every instance of a function call. However, substitution occurs only at the compiler's discretion. For example, the compiler does not inline a function if its address is taken or if it is too large to inline.
28.) What is overloading?
With the C++ language, you can overload functions and operators. Overloading is the practice of supplying more than one definition for a given function name in the same scope.
- Any two functions in a set of overloaded functions must have different argument lists.- Overloading functions with argument lists of the same types, based on return type alone, is an error.
29.) What is Overriding?
To override a method, a subclass of the class that originally declared the method must declare a method with the same name, return type (or a subclass of that return type), and same parameter list.The definition of the method overriding is:· Must have same method name.· Must have same data type.· Must have same argument list.Overriding a method means that replacing a method functionality in child class. To imply overriding functionality we need parent and child classes. In the child class you define the same method signature as one defined in the parent class.
30.) What is "this" pointer?
The this pointer is a pointer accessible only within the member functions of a class, struct, or union type. It points to the object for which the member function is called. Static member functions do not have a this pointer.
When a nonstatic member function is called for an object, the address of the object is passed as a hidden argument to the function. For example, the following function call
myDate.setMonth( 3 );
can be interpreted this way:
setMonth( &myDate, 3 );
The object's address is available from within the member function as the this pointer. It is legal, though unnecessary, to use the this pointer when referring to members of the class.
31.) Name the operators that cannot be overloaded??
sizeof, ., .*, .->, ::, ?:
32.) What happens when you make call "delete this;" ?
The code has two built-in pitfalls. First, if it executes in a member function for an extern, static, or automatic object, the program will probably crash as soon as the delete statement executes. There is no portable way for an object to tell that it was instantiated on the heap, so the class cannot assert that its object is properly instantiated. Second, when an object commits suicide this way, the using program might not know about its demise. As far as the instantiating program is concerned, the object remains in scope and continues to exist even though the object did itself in. Subsequent dereferencing of the pointer can and usually does lead to disaster.
You should never do this. Since compiler does not know whether the object was allocated on the stack or on the heap, "delete this" could cause a disaster.
33.) How virtual functions are implemented C++?
Virtual functions are implemented using a table of function pointers, called the vtable. There is one entry in the table per virtual function in the class. This table is created by the constructor of the class. When a derived class is constructed, its base class is constructed first which creates the vtable. If the derived class overrides any of the base classes virtual functions, those entries in the vtable are overwritten by the derived class constructor. This is why you should never call virtual functions from a constructor: because the vtable entries for the object may not have been set up by the derived class constructor yet, so you might end up calling base class implementations of those virtual functions
34.) What is name mangling in C++??
The process of encoding the parameter types with the function/method name into a unique name is called name mangling. The inverse process is called demangling.
For example Foo::bar(int, long) const is mangled as `bar__C3Fooil'.For a constructor, the method name is left out. That is Foo::Foo(int, long) const is mangled as `__C3Fooil'.
35.) What is the difference between a pointer and a reference?
A reference must always refer to some object and, therefore, must always be initialized; pointers do not have such restrictions. A pointer can be reassigned to point to different objects while a reference always refers to an object with which it was initialized.
36.) How are prefix and postfix versions of operator++() differentiated?
The postfix version of operator++() has a dummy parameter of type int. The prefix version does not have dummy parameter.
37.) What is the difference between const char *myPointer and char *const myPointer?
Const char *myPointer is a non constant pointer to constant data; while char *const myPointer is a constant pointer to non constant data.
38.) How can I handle a constructor that fails?
throw an exception. Constructors don't have a return type, so it's not possible to use return codes. The best way to signal constructor failure is therefore to throw an exception.
39.) How can I handle a destructor that fails?
Write a message to a
log-file. But do not throw an exception.The C++ rule is that you must never throw an exception from a destructor that is being called during the "stack unwinding" process of another exception. For example, if someone says throw Foo(), the stack will be unwound so all the stack frames between the throw Foo() and the } catch (Foo e) { will get popped. This is called stack unwinding.During stack unwinding, all the local objects in all those stack frames are destructed. If one of those destructors throws an exception (say it throws a Bar object), the C++ runtime system is in a no-win situation: should it ignore the Bar and end up in the } catch (Foo e) { where it was originally headed? Should it ignore the Foo and look for a } catch (Bar e) { handler? There is no good answer -- either choice loses information.So the C++ language guarantees that it will call terminate() at this point, and terminate() kills the process. Bang you're dead.
40.) What is Virtual Destructor?
Using virtual destructors, you can destroy objects without knowing their type - the correct destructor for the object is invoked using the virtual function mechanism. Note that destructors can also be declared as pure virtual functions for abstract classes.
if someone will derive from your class, and if someone will say "new Derived", where "Derived" is derived from your class, and if someone will say delete p, where the actual object's type is "Derived" but the pointer p's type is your class.
41.) Can you think of a situation where your program would crash without reaching the breakpoint
which you set at the beginning of main()?
C++ allows for dynamic initialization of global variables before main() is invoked. It is possible that initialization of global will invoke some function. If this function crashes the crash will occur before main() is entered.
42.) Can you overload a function based only on whether a parameter is a value or a reference?
No. Passing by value and by reference looks identical to the caller.
43.) What are the differences between a C++ struct and C++ class?
The default member and base class access specifiers are different.
The C++ struct has all the features of the class. The only differences are that a struct defaults to public member access and public base class inheritance, and a class defaults to the private access specifier and private base class inheritance.
44.) What does extern "C" int func(int *, Foo) accomplish?
It will turn off "name mangling" for func so that one can link to code compiled by a
C compiler.
45.) How do you access the static member of a class?
::
46.) What is multiple inheritance(virtual inheritance)? What are its advantages and disadvantages?
Multiple Inheritance is the process whereby a child can be derived from more than one parent class. The advantage of multiple inheritance is that it allows a class to inherit the functionality of more than one base class thus allowing for modeling of complex relationships. The disadvantage of multiple inheritance is that it can lead to a lot of confusion(ambiguity) when two base classes implement a method with the same name.
47.) What are the access privileges in C++? What is the default access level?
The access privileges in C++ are private, public and protected. The default access level assigned to members of a class is private. Private members of a class are accessible only within the class and by friends of the class. Protected members are accessible by the class itself and it's sub-classes. Public members of a class can be accessed by anyone.
48.) What is a nested class? Why can it be useful?
A nested class is a class enclosed within the scope of another class. For example:
// Example 1: Nested class//class OuterClass{class NestedClass{// ...};// ...};Nested classes are useful for organizing code and controlling access and dependencies. Nested classes obey access rules just like other parts of a class do; so, in Example 1, if NestedClass is public then any code can name it as OuterClass::NestedClass. Often nested classes contain private implementation details, and are therefore made private; in Example 1, if NestedClass is private, then only OuterClass's members and friends can use NestedClass.
When you instantiate as outer class, it won't instantiate inside class.
49.) What is a local class? Why can it be useful?
local class is a class defined within the scope of a function -- any function, whether a member function or a free function. For example:
// Example 2: Local class//int f(){class LocalClass{// ...};// ...};Like nested classes, local classes can be a useful tool for managing code dependencies.
50.) Can a copy constructor accept an object of the same class as parameter, instead of reference of the object?
No. It is specified in the definition of the copy constructor itself. It should generate an error if a programmer specifies a copy constructor with a first argument that is an object and not a reference.