Tuesday, November 10, 2009

Programming interview Questions and answers

Programming interview Questions and answers

How would you display a list box having a check box in front of each item?

Posted: 04 Nov 2009 06:29 PM PST

Ans: We come across a list box having check boxes many times while installing softwares like Microsoft Visual C++, MS-office etc. We can also implement such a list box and give a professional look to our application. This is how it can be done…

  • Derive a class, say, mycheckbox from CCheckListBox class.
  • Create an object of mycheckbox and call Create( ) function.
  • Add strings using CCheckListBox::AddString( ) function.
  • Run the application and you will see the list control with check boxes. You can interact with the control using member functions of CCheckListBox.

What is main() function in C Programming ?

Posted: 04 Nov 2009 06:25 PM PST

The execution of a C program begins with function named main(). All of the files and
libraries for the C program are compiled together to build a single program file. That file
must contain exactly one main() function which the operating system uses as the starting
point for the program. Main() returns an int which, by  convention, is 0 if the program
completed successfully and non-zero if the program exited due to some error condition.
This is just a convention which makes sense in shell oriented environments such as Unix
or DOS.

Can we execute a program without entering into main( ) function?

Posted: 04 Nov 2009 01:00 AM PST

Here is a program which ends before execution of main( ) function starts but still manages to get the output.

Basically all global objects are created before entering into main(); So you can write any code into the constructor of objects, which will be called whenever object is created.

class A


public :

A( )


cout << “In A” ;

exit( 1 ) ;


} ;

main( )


cout << “not reached” ;


A a ;

How to write multiline macro in C Language ?

Posted: 03 Nov 2009 10:59 PM PST

To write a multiline macro we have to use C’s line splitting character, the ‘\’.

Here is a macro definition of LINE and the program which uses it:

#define LINE for ( i = 0 ; i < 80 ; i++ )\

printf ( “_” ) ;\

printf ( “\n” ) ;

main( )


int i ;


printf ( “S.No         Roll No.        Name        Phy        Math        Chem\n” ) ;



The macro LINE draws a horizontal line on the screen.  The above program attempts to print the name of the fields of the students record in between the two lines. In the LINE macro we have used i as a variable hence, it has to be declared before we use the macro. Since we are using the macro in main( ) function, we have declared i before using the macro.

Displaying standard Properties dialog box

Posted: 03 Nov 2009 04:05 PM PST

If we right click on a file in Windows Explorer and select Properties from the popup menu it displays a dialog box showing all the properties of that file. We can display the Properties dialog box programmatically. Following code snippet will show Properties dialog box of abc.doc file which is in C drive.


sh.cbSize = sizeof ( sh ) ;


sh.lpVerb = “properties” ;

sh.lpFile = “C:\\abc.doc” ;

ShellExecuteEx ( &sh ) ;

How to find which processes are running on your system ?

Posted: 03 Nov 2009 03:59 PM PST

Many a times we need to see whether a particular application is running in the memory. We can get the information of processes running in the memory by using API functions Process32First( ) and Process32Next( )

as shown below.


HANDLE h = CreateToolhelp32Snapshot ( TH32CS_SNAPPROCESS, 0 ) ;

Process32First ( h, &pr ) ;



///Write your code///

} while ( Process32Next ( h, &pr ) ) ;

No comments:

Post a Comment