Sunday, 21 March 2010

ISOFT ASKED QUESTION FOR MANIVASAGAM

Download the original attachment

C++ Questions:

1. What is the default return type of the main function?

Int

2. How many arguments takes main function and what are they?

2 , argc and argv

3. what is pointer and advantages?

We can directly access the memory directly.

4. How many bytes takes the empty class and why?

1 byte, generally the compiler allocates the memory for the objects based on the datas of the class. If suppose we creates the empty class, we can able to create the instance. For that reason the empty class holds the one byte.

5. how many bytes take creating of pointer of char and int?

2bytes and 4 bytes. (based on the processor type)

6. OOPS concepts with real time examples
1. Class

Class is the blue print of the object creations. Eg. vehicles

2. Object

Object is the instance of the class, Eg. Bike car scooter

3. Polymorphism and its types

One interface multiple methods. Types, static and dynamic.

Static : overloading

Dynamic: virtual function

4. Inheritance

To create/derive a subclass from the base class. (we can extends the properties from base class to the derived classs).

5. Abstract class

A class contains atleast one pure virtual functions. We cant able to instantiate the object for the abstract class.

6. Pure virtual functions

If a virtual function is defined with the 0 then its pure virtual function/ (i.e) a virtual function with no body and initialized with 0)

Why u need pure virtual function?

If suppose we want to force the derived class to define the basic and common functions that time we need to create the pure virtual functions.

7. what is bindings and its types?
connection bw the function call and the actual code executed (YK book).

Static or earlier and dynamic or late.

Static : normal function call resolved at compile time

Dynamic : virtual functions.

8. what is virtual class and virtual constructor and virtual destructor

virtual constructor: there is no virtual constructor



virtual destructor: yes its available, its used to call all the destructor in the hiereachy of the class in which we derived.

Virtual class:

Its used for to avoid the ambiguity..

9. what is copy constructor and why this concept advantages?

To create a new copy of the object of the existing one.

Type : shallow and deep

Shallow – shallow shares the reference and pointers of existing object

Deep - deep will create and use its own memory of the existing ones copy.

Advantage:


10. difference between structure and class?

Default access specifier in structure is public , and for class private.


11. what is the difference between c and c++?

C is a procedure oriented and c++ is object oriented.

C doesn’t have the overloading concepts

(top and bottom appraich)

in c structure we must use the struct keyword while gets the object but c++ not in necessity

C C++

DATA IS NOT SECURED SECURED

TOP DOWN BOTTOM-UP

FOCUS ON PROCEDURES FOCUS ON DATA

PROGRAMS ARE DECOMPOSED INTO OBJECTS

INTO FUNCTIONS

allocation is done NEW OPERATOR

with malloc statement

UNOINS AND ENUMS AVALIABLE

ARE NOT AVALIABLE

DOES NOT PROVIDE PROVIDES

DEFAULT ARGUMENTS



12. What is friend function?

Its used to access the private data of the base class.

Uses:

Its used to access the private data of the base class.

Improves the versatile of the operator overloading.

13. what is friend class and its use?

We can share everything between any class while declare the class as friend..

14. what are all the operators that cant be overloaded?

.* , ?: , :: , . sizeof

15. what is overloading and overriding?

Overloading : same function name with may have different type or no of arguments, or different return type.

Overriding : same prototype will be used in the base and derived class.

16. different types of type casting.

Implicit – Implicit Conversion do not require any operator like int,double,float

Explicit - Explicit Conversion must require operator like int,double,float

Dynamic_cast - dynamic_cast can be used only with pointers and references to objects. Its purpose is to ensure that the result of the type conversion is a valid complete object of the requested class.

class CBase { };

class CDerived: public CBase { };

CBase b; CBase* pb;

CDerived d; CDerived* pd;

pb = dynamic_cast(&d); // ok: derived-to-base

pd = dynamic_cast(&b); // wrong: base-to-derived


Static_cast - static_cast can perform conversions between pointers to related classes, not only from the derived class to its base, but also from a base class to its derived

Reinterpret_cast - reinterpret_cast converts any pointer type to any other pointer type, even of unrelated classes.

Constructor`

A constructor is a special member function which will construct an object with user defined values whenever object is created OR A constructor is a special member function which will be called automatically to initialize the data member of a class whenever object is instantiated.



when can we use copy constructor?

A copy constructor is used in 3 cases.They are listed below:

a)When an object is created from another object of the same

type.

b)When an object is passed by value as a parameter to a

function.

c)When an object is returned from a pointer.

no virtual constructor y?

A constructor cant be virtual. Bcoz at a time when the constructor is invoked from the virtual table wouldn’t be available in memory.

Virtual function is slow y?

Because if we use the virtual functions then the vtable is created and when we call the virtual functions it will refere the vtable vptr for the first two bytes of the object that contains.

So that acess of the vtable causes the slow processing.


stack , queue

stack:

Inserting and deleting the element using TOP. This is Last In First Out.(LIFO)

Queue:

Insert the element using Front and Deleting the Element using Rear. This is First In First Out(FIFO)

virtual functions is slow, why?

malloc calloc new

malloc:]

default memory value is Garbage

calloc:

default memory value is zero.

New :

When we use the new operator the constructor is call

VC++

1. What is the base class for all classes in the mfc?

CObject

CObject does not support multiple inheritance. Your derived classes can have only one CObject base class, and that CObject must be leftmost in the hierarchy. It is permissible, however, to have structures and non-CObject-derived classes in right-hand multiple-inheritance branches.

Its functionalities,

Serialization, - Storing/Restoring object to or from persistent storage such as disk drive.

Runtime class information – to identify the base class information at run time using CRunTime class.

Object diagnostic support – Assert(), Dump(), TRACE(), VERIFY(), DEBUG-NEW,

AfxDump, AfxMemDef, AfxCheckError.

http://msdn.microsoft.com/en-us/library/s8c29sw2%28VS.71%29.aspx

Compatablity with collection class. – Array , List, CStringArray, CByteArray, CMap

2. why CObject is the base class for almost all classes?

Ba abababababababaabba

3. how to achieve serialization?

File read write using CFile

CArchieve

4. Did you use any CObject method in ur class?

Yes, used. Like DYNA_CREATE, DECLARE_DYNAMIC, IMPLEMENT_DYNAMIC.

5. what is the difference between managed and unmanaged?

Manged – .Net (CLR)

Un managed - Native c++

6. How to find out either managed or unmanaged code?




7. What is the default method called in dialogbased application either ‘OnOK’ or ‘Oncancel’?

OnOK()

8. How OnOK get proceed as default?



9. what is model and modeless dialog?

In modal dialog we cant get focus to the parent while using the child window.

But in case of the modeless dialog we can able to access both dialogs.

10. How to create the modeless dialog?

Using Create() and ShowWindow().

11. if application opened two modeless dialog what is the default method called?

OnOK()

12. if I opened two modeless dialog then I close parent dialog and I want to close the its modeless dialog also, how to handle this?



DestroyWindow(). Store all the window handle with the list and destroy the individual child window before close the parent.

http://www.codeproject.com/KB/dialog/gettingmodeless.aspx


13. What is message map? How many arguments takes BEGIN_MESSAGE_MAP and why?

MessageMap is macro used to handle messages by calling appropriate functions.

Begin messagemap - > 2 arguments, class name, class base class…

Base class is needed because if that class doesn’t have that particular message defined then the base class message is to be processed. And its continues to find the message if suppose nothing found then the default should be called.

14. DodataExcahange ()

DoDataExcahange is used to map the datas and then the controls. We can manually call this witht the help of the UpdateData().

By default its arg is true. If its true – then values copied from the control to the member variable, and if its false then the member variable to the control is to be updated.

15. what is afx stands for?

Afx stands for Application Framework

16. Explain function prototype of the AfxMessageBox() and AfxBeginThread()?

AfxMessageBox(CString message,uint ntype, uint nhelpid);

MessageBox(CString strDisplayString, CString strTitle, UINT nType);

AfxBeginThread: (

CWinThread* AfxBeginThread(

AFX_THREADPROC pfnThreadProc,

LPVOID pParam,

int nPriority = THREAD_PRIORITY_NORMAL,

UINT nStackSize = 0,

DWORD dwCreateFlags = 0,

LPSECURITY_ATTRIBUTES lpSecurityAttrs = NULL

);

CWinThread* AfxBeginThread(

CRuntimeClass* pThreadClass,

int nPriority = THREAD_PRIORITY_NORMAL,

UINT nStackSize = 0,

DWORD dwCreateFlags = 0,

LPSECURITY_ATTRIBUTES lpSecurityAttrs = NULL

);


17. How many types of thread and what is the different?

Two types:

Worker Thread and user interface Thread.

Worker Thread can run with out user interaction.

User Interface Thread it can have user input.

18. How many classes gets created on dialog based application and what are they?

Dlg class and application class

Dlg class – CDialog base class

App class - CWinApp base class

19. How to check particular exe opened or not ? what method?

EnumProcess().

20. What is DefWndProc()? And how to handle messages

Sends the specified message to the default window procedure.

21. what is function overloading? And over riding?

Overloading – same functions with different types of arguments or no of arguments

Over riding- same function with same arguments and types of arguments.

This is involves in the inheritance concepts.

22. how many ways achieve the compile time polymorphism

Function Overloading and operator overloading.



23. What is the different between the sendmessage and postmessage?

Send Message :

The SendMessage function places a message in the

message queue waiting for the thread to process the message.


Post Message:

The PostMessage function places (posts) a message in the

message queue associated with the thread that created the

specified window and then returns without waiting for the

thread to process the message.

24. Whats the PreTranslateMessage and its use.?



25. what is smart pointer?
26. RTTI

Run time type identification

Used to identify the base class type for object. Using typeid or dynamic_cast().

27. Clistctrl and CListView

List ctrl we can use report and icon views

Listbox is normal like to store datas in list.

28. Function Pointer / call back

We can call the function with the address of that particular function.

Call back is calling a function using the function pointer

29. What is DC



30. CClientDC and CPaintDC
31. CDC and HDC
32. Handle to Window
33. Collection Classes.



COM

1. What is COM?

Component Object Model, It’s a language neutral.

Adv: Act as a interface between two different modules.

2. What are the methods available in COM? That is common for all interfaces?

AddRef – Reference count increase

Release – Decrease count, if =0 then release the object from memory.

QueryInterface – obtain the interface object.

3. What is the base interface?

IUnknown

4. How the com dll map the string from vb to vc++



5. Advantages of COM?

Adv: Act as a interface between two different modules.

Easily communicate between two modules.


6. How to obtain the object of the interface?

Using CoCreateInstance().

7. What is and the return type of the CoCreateInstance()?

HRESULT


.NET:

1. What is web service?
2. What is CLR?

Common Language Runtime

3. What type of architecture you used in your web service?



4. What is the base class of web service?

System.Service

5. How the web service get process the client request?




Data Base:

1. What is the Primary Key?

Uniquely identify the record.

Primary doesn’t allows not null but unique allows the null value.

Foreign key – creating keys for the two tables with the primary key of the first table.

2. What is Index?

Index created for the fast access to the data. For most cases the primary will be used for the index.

3. what is join? And advantages?

To obtain the details of records from two tables

Types:

Inner join

Outer join

Left outer

Right outer

Sunday, 25 October 2009

C PROGRAMMING TUTORIAL

INDEX
Chapter 1 Memory map
Chapter 2 Data type
Chapter 3 Variables in c
Chapter 4 Operators and expression
Chapter 5 Control structure if else and switch case
Chapter 6 Looping in c for, while, do while
Chapter 7 Array
Chapter 8 Pointer
Chapter 9 String
Chapter 10 Functions
Chapter 11 C Preprocessor
Chapter 12 Structures
Chapter 13 Union
Chapter 14 File handling
Chapter 15 Input output
Chapter 16 Command line arguments
Chapter 17 Advance C
Chapter 18 Traditional questions of c programming
Chapter 19 Quiz in C
Chapter 20 Data structure
Chapter 21 Objective questions of c proramming
Chapter 22 Mutiple choice questions of c
Chapter 23 Test your self
Chapter 24 Assembly language programming in c

c programming quiz with solution

Time: 6 minute
-------------------------------------------------

(1)

void main(){

float a=30.3f;

int y=5;

clrscr();

printf("%d",a%y);

getch();

}

What will be output when you will compile above code?

(a) 6

(b) 6.0

(c) 7

(d) Compiler error

(e) None of these
-------------------------------------------------
(2)

void main(){

int x=5;

float r=5.0;

clrscr();

printf("%x %X %o",sizeof(x,r),sizeof(r,x),sizeof(sizeof(5.0)));

getch();

}

What will be output when you will compile above code?

(a) 4 2 2

(b) 2 4 4

(c) 2 4 2

(d) Compiler error

(e) None of these
-------------------------------------------------
(3)

void main(){

int y=15,z=25;

function(&y,&z);

clrscr();

printf("%d\t%d",z,y);

getch();

}

function (int *p,int *q){

return(*p=(*p+*q)-(*q=*p));

}

What will be output when you will compile above code?

(a) 25 15

(b) 15 25

(c) 25 25

(d) Compiler error

(e) None of these
-------------------------------------------------
(4)

void main(){

int a=-1;

static int count;

clrscr();

while(a){

count++;

a&=a-1;

}

printf("%d",count);

getch();

}

What will be output when you will compile above code?

(a) 15

(b) 16

(c) 17

(d) Compiler error

(e) None of these
-------------------------------------------------
(5)

void main(){

typedef float arr[10];

arr b={2,4,6};

clrscr();

printf("%d",sizeof(b));

getch();

}

What will be output when you will compile above code?

(a) 40

(b) 12

(c) 4

(d) Compiler error

(e) None of these
-------------------------------------------------
(6)

void change(int const *p){

*((int *)p)=20;

}

void main(){

int const x=10;

change(&x);

clrscr();

printf("%d",x);

getch();

}

What will be output when you will compile above code?

(a) 10

(b) 20

(c) 30

(d) Compiler error

(e) None of these




Solution:

(1)(d) Modular division is only possible for integral data type

(2)(a)

(3)(b)

(4)(b)

(5)(a)

(6)(b)

Note: If you want to explanation of any questions you can ask through comment.

MCQ Questions in c

C ,C++, SQL,PL/SQL Search Engine
-------------------------------------------------
Custom Search
Java,Advance Java,Java script and ebook Search Engine

Big collection of c and java questions
Explanations of questions in easily way
MCQ Questions in c

-------------------------------------------------
(1)
void main(){
clrscr();
printf("%d",sizeof(3.8));
getch();
}

Which of the following is true?
(a)4
(b)8
(c)10
(d)Compiler error
(e)None of these

-------------------------------------------------
(2)
void main(){
char *str1="powla";
char *str2="er";
clrscr();
printf("%s\b\b%s",str1,str2);
getch();
}

Which of the following is true?
(a)powlaer
(b)pow
(c)power
(d)Compiler error
(e)None of these
-------------------------------------------------
(3)
void main(){
int a=270;
char *p;
p=(char *)&a;
clrscr();
printf("%d",*p);
getch();
}
Which of the following is true?
(a)270
(b)address of variable a
(c)16
(d)Compiler error
(e)None of these
-------------------------------------------------
(4)
What is missing statement of in the following program?
void main(){
int sort(int,int);
int I;
i=sort(5,6);
}
int sort(int a,int b){
int c;
c=a;
a=b;
b=c;
return a;
}
-------------------------------------------------
(5)Write following in term of if and else:
void main(){
int a=1,b=2,c=3;
clrscr();
if(a==5&&b==6&&c==7)
printf("india");
else
printf("pak");
getch();
}
-------------------------------------------------
(6)
Draw memory representation of
struct xxx{
char a;
int b;
char c;
};
-------------------------------------------------
(7)
Write the following program in term of switch and case?
void main()
{
int a=3;
if(x>2){
printf(“INDIA IS BEST”);
}
else{
printf(“PAK IS BEST”);
}
}
-------------------------------------------------
(8)
void main(){
int far *a=(int far*)0x50000011;
int far *b=(int far*)0x50010001;
int huge *c=(int huge*)0x50000011;
int huge *d=(int huge*)0x50010001;
clrscr();
if(a==b)
printf("I know C");
else
printf("I don't know C");
if(c==d)
printf("\nI know C");
else
printf("\nI don't know C");
getch();
}
Which of the following is true?
(a)I know C
I Know C
(b)I know C
I don’t know C
(c)I don’t know C
I know C
(d)Compiler error
(e)None of these
-------------------------------------------------
(9)
#define power(a) #a
void main(){
clrscr();
printf("%d",*power(432));
getch();
}
Which of the following is true?
(a)*”432”
(b)432
(c)16
(d)32
(e)Compiler error
-------------------------------------------------
(10)
void main(){
int arr[]={1,2,3,4,5,6};
void xxx(int[5]);
xxx(arr);
getch();
}
void xxx(int ch[5]){
clrscr();
printf("%d",-1[ch]);
}
Which of the following true?
(a)2
(b)-2
(c)3
(d)-3
(e)Compiler error
-------------------------------------------------
(11)
What is difference between a, b, c and in following declaration ?
#define xxx char *
typedef char * yyy;
void main(){
yyy a,b;
xxx c,d;
}
-------------------------------------------------
(12)
Write a c program to find the HCF of any two numbers?
-------------------------------------------------
(13)
void main(){
int a=5;{
a++;
}
clrscr();
printf("%d",a);
getch();
}
Which of the following is true?
(a)5
(b)6
(c)7
(d)Compiler error
(e)None of these
-------------------------------------------------
(14)
void main(){
int a=5;{
int a=7;
a++;
printf(“%d”,a);
}
clrscr();
printf("%d",a);
getch();
}
Which of the following is true?
(a)5 7
(b)5 8
(c)8 5
(d)7 5
(e)Compiler error

-------------------------------------------------
-------------------------------------------------
Answer:
(1)(b)
(2)(c)
(3)(c)
(4) See in explanation.
(5) See in explanation.
(6) See in explanation.
(7) See in explanation.
(8)(c)
(9)(c)
(10)(b)
(11) See in explanation.
(12) See in explanation.
(13)(b)
(14)(c)
-------------------------------------------------
Explanation:
-------------------------------------------------
(1) 3.8f is float constant, 3.8 is double constant and 3.8L is long double constant .Here are finding size of double constantan which is 8.
(2) \b escape sequence back the cursor one position left .We are using two /b so after writing str1 cursor is at the position of l of powal .So when it write er it will override the la so output will be power.
(4) Function sort returning a value but we are not using return value so there is wastage of two byte memory. So missing statement is, there should statement which uses the return value.
(5)
void main(){
int a=1,b=2,c=3;
clrscr();
if(a==1){
if(b==2){
if(c==3){
printf("india");
}
else{
printf("pak");
}
}
else{
printf("pak");
}
}
else{
printf("pak");
}
getch();
}
(7)if condition always return two value.
1 if condition is true.
0 if condition is false.
So program is
void main(){
int x=3;
switch(x>2){
case 0:printf("India is best");
break;
case 1:printf("Pak is best");
}
getch();
}
(8)
far pointer always compare its whole far address. Since both or not equal so first output is: I don’t know C
Huge pointer always compare its physical address both c and d are representing same physical address so a and b are equal.
(9) # is string zinging operator. It makes the string constant of any data. So 432 is converted into “432” by macro power .Now *”432” means first char which is 4.Since we are using %d so it will print ASCII value of char 4 i.e. 52
(10) We are passing the array by xxx function. 1[ch] means *(ch+1) which is ch[1] =2.
(11) Both and b are char * type but c is char * type while d is char type.
(12) void main(){
int a,b,c;
scanf(“%d%d%d”,a,b,c);
clrscr();
while((c=a%b)!=0){
a=b;
b=c;
}
printf("%d",b);
getch();
}
(14) Scope of the auto variable is within {} if it is declared in {}.Also local variable has more priority than global variable.

-------------------------------------------------

FAQ questions in c programming

FAQ questions in c programming
-------------------------------------------------
Using only c programming language
-------------------------------------------------
check given number is prime number or not using

check the given number is armstrong number or not

check the given number is palindrome number or not

CHECKING LEAP YEAR

CHECK STRING IS PALINDROME OR NOT

PASSING ONE-DIMENSIONAL ARRAY TO A FUNCTION

CREATE A FILE AND STORE DATA IN IT

TO PASSING 2-DIMENSIONAL ARRAY TO A FUNCTION

WRITING OF STRINGS TO A FILE

READING OF STRINGS FROM A FILE

WRITING OF ENTIRE ARRAY TO A FILE

CONCATENATE MANY FILES AND STORE THEM IN A FILE NAMED FILES

SWAPPING OF STRINGS

SWAP TWO VARIABLES WITHOUT USING THIRD USING VARIABLE

SWAPING OF TWO ARRAYS USING C PROGRAM

CONCATENATE MANY FILES AND STORE THEM IN A FILE NAMED FILES

FIND PRIME FACTORS OF A NUMBER

TO FIND MULTIPLICATION TABLE

TO FIND FACTORIAL OF A NUMBER

TO FIND FIBONACCI SERIES

PRINTING ASCII VALUE USING

CONVERSION OF DECIMAL TO BINARY

CONVERSION OF BINARY TO DECIMAL

CONVERSION FROM DECIMAL TO OCTAL

CONVERSION FROM UPPERCASE TO LOWER CASE

CONVERSION FROM LOWER CASE TO UPPER CASE

CONVERSION OF FAREHNITE TO CENTIGRADE

DELETE THE VOWELS FROM A STRING

ADDITION OF TWO MATRICES

COPY DATA FROM ONE FILE TO ANOTHER FILE

ADDITION & SUBTRACTION OF TWO COMPLEX NUMBERS

FIND SUM OF THE SERIES 1+2+3+---------+n

FIND OUT LARGEST NUMBER IN AN ARRAY

FIND OUT SECOND LARGEST NUMBER IN AN UNSORTED ARRAY

MULTIPLICATION OF TWO MATRICES

FIND OUT SUM OF DIAGONAL ELEMENTS OF A MATRIX

FIND OUT TRASPOSE OF A MATRIX

find out the perfect number

COUNTING DIFFERENT CHARACTERS IN A STRING

DISPLAY SOURCE CODE AS OUTPUT

FIND FACTORIAL OF A NUMBER USING RECURSION

FIND GCD OF A NUMBER USING RECURSION

FIND SUM OF DIGITS OF A NUMBER USING RECURSION

FIND POWER OF A NUMBER

FIND POWER OF A NUMBER USING RECURSION

CONCATENATION OF TWO STRINGS USING POINTER

CONCATENATION OF TWO STRINGS
SORTING OF STRING

BUBBLE SORT
SELECTION SORT

INSERTION SORT

QUICK SORT

LINEAR SEARCH

BINARY SEARCH

BINARY SEARCH THROUGH RECURSSION

REMOVE DUPLICATE ELEMENTS IN AN ARRAY

REVERSE A NUMBER USING RECURSION

DELETE ELEMENT FROM AN ARRAY AT DESIRED POSITION

FIND GREATEST AMONG 3 NUMBERS USING CONDITIONAL OPERATOR

FIND OUT GENERIC ROOT OF A NUMBER

find g.c.d of two number
find sum of the digit of number
reverse any number

Write a scanf statement which can store one line of string which includes white space ?

HOW can TAKE a paragraph at time USING scanf FUNCTION?

STRING QUESTIONS AND ANSWER IN C

(1) Without using any semicolon (;) in program write a c program which output is: HELLO WORLD?
Answer:
void main()
{
if(printf("HELLO WORLD"))
{
}
}
(2)What will be output of following code?
void main()
{
char a[5];
a[0]='q';
a[1]='u';
a[2]='e';
clrscr();
printf("%s",a);
getch();
}
Output: garbage
Explanation: %s is used for string but a is not a string it is only array of character since its last character is not null character.
If you will write a[3]=’\0’; then output will be que.
(3) Write a scanf statement which can store one line of string which includes white space.
Answer:
void main()
{
char a[30];
clrscr();
scanf("%[^\n]",a);
printf("%s",a);
getch();
}
(4) Write a c program in which a scanf function can store a paragraph at time?
Answer:
void main()
{
char a[30];
clrscr();
scanf("%[^\t]",a);
printf("%s",a);
getch();
}
Note: Paragraph will end when you will press tab key.
(5)In the following program
void main()
{
extern char a[30];
}
How much array a is reserving memory space?
Answer:
It is not reserving any memory space because array a has only declared it has not initialized .Any not initialized variable doesn’t reserve any memory space.

FAQ questions of preprocessor in c

Question section
(1)
What will be output of following code?
#define max 10
void main()
{
int i;
i=++max;
clrscr();
printf("%d",i);
getch();
}
(2)
What will be output of following code?
#define max 10+2
void main()
{
int i;
i=max*max;
clrscr();
printf("%d",i);
getch();
}
(3)
What will be output of following code?
#define A 4-2
#define B 3-1
void main()
{
int ratio=A/B;
printf("%d ",ratio);
getch();
}
(4)
What will be output of following code?
#define MAN(x,y) (x)>(y)?(x):(y)
void main()
{
int i=10,j=9,k=0;
k=MAN(i++,++j);
printf("%d %d %d",i,j,k);
getch();
}
(5)
What will be output of following code?
#define START main() {
#define PRINT printf("*******");
#define END }
START
PRINT
END
(6)
What will be output of following code?
#define CUBE(x) (x*x*x)
#define M 5
#define N M+1
#define PRINT printf("RITESH");
void main()
{
int volume =CUBE(3+2);
clrscr();
printf("%d %d ",volume,N);
PRINT
getch();
}
Best questions of preprocessor questions
Big collection of preprocessor questions
Solution section
To read theory click here

(1)
output: compiler error.
explanation:
max is preprocesor macro which process first before the actual compilation.
preprocessor paste the symbol to the its constant value in entire the program before the compilation.so in this progrom max will be replaced by 10 before compilation.Thus program will be converted as:

void main()
{
int i;
i=++10;
clrscr();
printf("%d",i);
getch();
}

To know how we can see intermediate file click here
In this program we are trying to incrment a constant symbol.
meanig of ++10 IS :-
10=10+1
or 10=11
which is error because we cannot assigne constant value to another constant value .Hence compiler will give error.

(2)
output: 32

explanation:
max is preprocesor macro which process first before the actual compilation.
preprocessor paste the symbol to the its constant value without any calulation in entire the program before the
compilation.so in this progrom max will be replaced by 10+2 before compilation.Thus program
will be converted as:


void main()
{
int i;
i=10+2*10+2;
clrscr();
printf("%d",i);
getch();
}

now i=10+2*10+2
i=10+20+2
i=32

(3)
output : 3
explanation:

A and B preprocesor macro which process first before the actual compilation.
preprocessor paste the symbol to the its constant value without any calculation in entire the program before the
compilation.so in this progrom A and B will be replaced by 4-2 and 3-1 respectively before compilation.Thus program
will be converted as:


void main()
{
int ratio=4-2/3-1;
printf("%d ",ratio);
getch();
}


here ratio=4-2/3-1
ratio=4-0-1
ratio=3

(4)
output: 11 11 11

explanation:
Preprocesor macro which process first before the actual compilation.
preprocessor paste the symbol to the its constant value without any calculation in entire the program before the
compilation.Thus program will be converted as:


void main()
{
int i=10,j=9,k=0;
k=(i++)>(++j)?(i++):(++j);
printf("%d %d %d",i,j,k);
getch();
}

now k=(i++)>(++j)?(i++):(++j);
first it will check the condion
(i++)>(++j)
i++ i.e when postfix is used with variable in expression then expression is evaluated first with original
value then variable is incemented
or 10>10
this condition is false.
now i=10+1=11
there is rule , only false part will execute after ? i.e ++j ,i++ will be not execute.
so after ++j
j=10+1=11;
and k will assign value of j .so k=11;

(5)
output: *******
explanation:
Preprocesor macro which process first before the actual compilation.
preprocessor paste the symbol to the its constant value i.e symbol without any calculation in entire the program before the compilation.Thus program will be converted as:


main()
{
printf("*******");
}
(6)
output: 17 6
explanation:
Preprocessor macro which process first before the actual compilation.
preprocessor paste the symbol to the its constant value without any calculation in entire the program before the compilation.Thus program will be converted as:

void main()
{
int volume =(3+2*3+2*3+2);
clrscr();
printf("%d %d ",volume,5+1);
PRINT
getch();
}