#define swap1(a,b) a=a+b;b=a-b;a=a-b;
main()
{
int x=5,y=10;
swap1(x,y);
printf("%d %d\n",x,y);
swap2(x,y);
printf("%d %d\n",x,y);
}

int swap2(int a,int b)
{
int temp;
temp=a;
b=a;
a=temp;
return;
}

what are the outputs?

Answer Posted / jaroosh

Result of the above program will probably be sth like :
compile error `return' with no value, in function returning
non-void
or
function swap2(...) should return a non-void value.
thats because from the erroneous code YOU CANT PREDICT what:
return;
in swap2 function was about to return.
It may sound that Im picking, but as an interviewer myself,
I have to say it is CRUCIAL on an interview to pinpoint
errors in the code, NEVER assume that its just a
misspelling, some of those errors are, some of them aren't
and are there to check if you read code thoroughly, its
always better to point such things.

Assuming the code was right and the swap2 signature was
void swap2(int a, int b)
code result will be :
10 5
10 5
switching values of a and b in swap2 doesnt affect x and y
values in program because they are being passed BY VALUE to
swap2.

Is This Answer Correct ?    7 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Why pointers are used in c?

576


What is a function simple definition?

602


What is memcpy() function?

613


Write a C program to accept a matrix of any size. Find the frequency count of each element in the matrix and positions in which they appear in the matrix

1505


Is there anything like an ifdef for typedefs?

692






I just typed in this program, and it is acting strangely. Can you see anything wrong with it?

548


How can you increase the size of a statically allocated array?

603


general for is %wd,f-d; in this system "w" means a) 'w' represent total width of digits b) 'w' represent width which includes the digits before,after decimal place and the decimal point c) 'w' represent width which includes the digits before only d) 'w' represent width after decimal place only

576


Input is "rama loves rajesh and rajesh Loves rama also and rajesh wear gloves and bloves" To print output is count the numbers of times repeted the word love without case sensitive.

1575


What is the collection of communication lines and routers called?

603


my project name is adulteration of chille powder.how can i explain it to the hr when he asks me about the project?

1105


What are the basic data types associated with c?

803


Explain indirection?

631


write a program to print largest number of each row of a 2D array

1860


What do you mean by keywords in c?

613