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

Write a program to generate the Fibinocci Series

0 Answers   TISL,


can anyone please tell about the nested interrupts?

0 Answers  


#include<stdio.h> main() { int a[3]; int *I; a[0]=100;a[1]=200;a[2]=300; I=a; Printf(“%d\n”, ++*I); Printf(“%d\n”, *++I); Printf(“%d\n”, (*I)--); Printf(“%d\n”, *I); } what is the o/p a. 101,200,200,199 b. 200,201,201,100 c. 101,200,199,199 d. 200,300,200,100

1 Answers  


What is the most efficient way to store flag values?

0 Answers  


Why is C language being considered a middle level language?

0 Answers  






Is the C language is the portable language...If yes...Then Why...and if not then what is problem so it is not a Portable language..???

2 Answers   TCS,


How does C++ help with the tradeoff of safety vs. usability?

1 Answers  


Explain enumerated types in c language?

0 Answers  


palindrome for strings and numbers----Can anybody do the prog?

6 Answers   CTS, TCS, Vipro Lifescience Pvt,


in linking some of os executables are linking name some of them

0 Answers   IBM,


Write a C program linear.c that creates a sequence of processes with a given length. By sequence it is meant that each created process has exactly one child. Let's look at some example outputs for the program. Here the entire process sequence consists of process 18181: Sara@dell:~/OSSS$ ./linear 1 Creating process sequence of length 1. 18181 begins the sequence. An example for a sequence of length three: Sara@dell:~/OSSS$ ./linear 3 Creating process sequence of length 3. 18233 begins the sequence. 18234 is child of 18233 18235 is child of 18234 ........ this is coad .... BUt i could not compleate it .....:( #include <stdio.h> #include <sys/types.h> #include <unistd.h> #include <stdlib.h> int main(int argc, char *argv[]) { int N; pid_t pid; int cont; if (argc != 2) { printf("Wrong number of command-line parameters!\n"); return 1; } N = atoi(argv[1]); printf("Creating process sequence of length %d.\n",N); printf("%d begins the sequence.\n",getpid()); /* What I have to do next ?????? */ }

0 Answers  


write a c program for greatest of three numbers without using if statment

4 Answers   IBM,


Categories