Follow Our FB Page << CircleMedia.in >> for Daily Laughter. We Post Funny, Viral, Comedy Videos, Memes, Vines...


#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?

Answers were Sorted based on User's Feedback



#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\..

Answer / goodhunter

10 5
10 5

Is This Answer Correct ?    19 Yes 2 No

#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\..

Answer / 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

#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\..

Answer / mannucse

10 5
5 10

Is This Answer Correct ?    9 Yes 10 No

#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\..

Answer / chitra

10 5
5 5

Is This Answer Correct ?    3 Yes 9 No

Post New Answer

More C Interview Questions

what is the maximum no. of bytes calloc can allocate

4 Answers   Mphasis,


Why do we use return in c?

0 Answers  


define string ?

0 Answers  


Why doesnt that code work?

0 Answers  


how to swap two integers 1 and 32767 without using third variable

11 Answers   Microsoft, TCS,






Why is struct padding needed?

0 Answers  


what is the advantage of software development

1 Answers  


Write the control statements in C language

0 Answers   Atos Origin,


Why does the call char scanf work?

0 Answers  


Write a function stroverlap that takes (at least) two strings, and concatenates them, but does not duplicate any overlap. You only need to worry about overlaps between the end of the first string and the beginning of the second string. Examples: batman, manonthemoon = batmanonthemoon batmmamaman, mamamanonthemoon = batmmamamanonthemoon bat, man = batman batman, batman = batman batman, menonthemoon = batmanmenonthemoon

0 Answers   HCL,


write a program for even numbers?

19 Answers   TCS,


How can a process change an environment variable in its caller?

0 Answers  


Categories