#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
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 |
main() { int x=5; printf("%d %d %d\n",x,x<<2,x>>2); }
11 Answers CISOC, CitiGroup, College School Exams Tests,
i have to apply for the rbi for the post of officers. i need to know abt the entrance questions whether it may be aps or techinical....
.main() { char *p = "hello world!"; p[0] = 'H'; printf("%s",p); }
How do I declare an array of N pointers to functions returning pointers to functions returning pointers to characters?
wat is the output int main() { char s1[]="Hello"; char s2[]="Hello"; if(s1==s2) printf("Same"); else printf("Diff"); }
Why is this loop always executing once?
How can you read a directory in a C program?
If the size of int data type is two bytes, what is the range of signed int data type?
pierrot's divisor program using c or c++ code
Write a programme to find even numbers without using any conditional statement?
3 Answers ADD Software, Infosys,
What is const keyword in c?
why should i select you?