main()

{

void swap();

int x=10,y=8;

swap(&x,&y);

printf("x=%d y=%d",x,y);

}

void swap(int *a, int *b)

{

*a ^= *b, *b ^= *a, *a ^= *b;

}

Answers were Sorted based on User's Feedback



main() { void swap(); int x=10,y=8; swap(&x,&y); ..

Answer / susie

Answer :

x=10 y=8

Explanation:

Using ^ like this is a way to swap two variables without
using a temporary variable and that too in a single statement.

Inside main(), void swap(); means that swap is a function
that may take any number of arguments (not no arguments) and
returns nothing. So this doesn’t issue a compiler error by
the call swap(&x,&y); that has two arguments.

This convention is historically due to pre-ANSI style
(referred to as Kernighan and Ritchie style) style of
function declaration. In that style, the swap function will
be defined as follows,

void swap()

int *a, int *b

{

*a ^= *b, *b ^= *a, *a ^= *b;

}

where the arguments follow the (). So naturally the
declaration for swap will look like, void swap() which means
the swap can take any number of arguments.

Is This Answer Correct ?    4 Yes 0 No

main() { void swap(); int x=10,y=8; swap(&x,&y); ..

Answer / shruthi

x=8,y=10

Is This Answer Correct ?    3 Yes 0 No

Post New Answer

More C Code Interview Questions

main() { int i = 0xff ; printf("\n%d", i<<2); } a. 4 b. 512 c. 1020 d. 1024

2 Answers   HCL,


main() { char str1[] = {‘s’,’o’,’m’,’e’}; char str2[] = {‘s’,’o’,’m’,’e’,’\0’}; while (strcmp(str1,str2)) printf(“Strings are not equal\n”); }

1 Answers  


Code for 1>"ascii to string" 2>"string to ascii"

1 Answers   Aricent, Global Logic,


How do I write a program to print proper subset of given string . Eg :input: abc output:{},{a},{b},{c},{a,b},{a,c},{b,c}, {a,b,c}.I desperately need this program please mail me to saravana6m@gmail.com

11 Answers   Deshaw, Infosys,


Program to find the largest sum of contiguous integers in the array. O(n)

11 Answers  






Give a oneline C expression to test whether a number is a power of 2?

25 Answers   EA Electronic Arts, Google, Motorola,


#include<stdio.h> int main() { int a=3,post,pre; post= a++ * a++ * a++; a=3; pre= ++a * ++a * ++a; printf("post=%d pre=%d",post,pre); return 0; }

3 Answers  


Write a program to implement the motion of a bouncing ball using a downward gravitational force and a ground-plane friction force. Initially the ball is to be projected in to space with a given velocity vector

2 Answers  


Write a Program in 'C' To Insert a Unique Number Only. (Hint: Just Like a Primary Key Numbers In Database.) Please Some One Suggest Me a Better Solution for This question ??

0 Answers   Home,


main() { static int var = 5; printf("%d ",var--); if(var) main(); }

1 Answers  


how to swap 3 nos without using temporary variable

4 Answers   Satyam,


Develop a routine to reflect an object about an arbitrarily selected plane

0 Answers  


Categories