#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

What is difference between structure and union in c programming?

571


Write a program to reverse a given number in c language?

620


How do we print only part of a string in c?

587


Why c is faster than c++?

634


How would you obtain the current time and difference between two times?

730






What does it mean when a pointer is used in an if statement?

602


What is int main () in c?

627


what is a constant pointer in C

680


Explain what are the different file extensions involved when programming in c?

635


Why do we use header files in c?

585


What is the equivalent code of the following statement in WHILE LOOP format?

769


Give the rules for variable declaration?

678


Where is volatile variable stored?

652


write a C program: To recognize date of any format even formats like "feb-02-2003","02-february-2003",mm/dd/yy, dd/mm/yy and display it as mm/dd/yy.

3342


What is an arrays?

656