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

How to return multiple values from a function?

7 Answers  


#ifdef something int some=0; #endif main() { int thing = 0; printf("%d %d\n", some ,thing); }

1 Answers  


main() { int *j; { int i=10; j=&i; } printf("%d",*j); }

9 Answers   HCL, Wipro,


#if something == 0 int some=0; #endif main() { int thing = 0; printf("%d %d\n", some ,thing); }

1 Answers  


# include <stdio.h> int one_d[]={1,2,3}; main() { int *ptr; ptr=one_d; ptr+=3; printf("%d",*ptr); }

1 Answers  






plz send me all data structure related programs

2 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  


main() { signed int bit=512, i=5; for(;i;i--) { printf("%d\n", bit >> (i - (i -1))); } } a. 512, 256, 0, 0, 0 b. 256, 256, 0, 0, 0 c. 512, 512, 512, 512, 512 d. 256, 256, 256, 256, 256

2 Answers   HCL,


#define square(x) x*x main() { int i; i = 64/square(4); printf("%d",i); }

4 Answers   Google, HCL, Quick Heal, WTF,


int main() { int x=10; printf("x=%d, count of earlier print=%d", x,printf("x=%d, y=%d",x,--x)); getch(); } ================================================== returns error>> ld returned 1 exit status =================================================== Does it have something to do with printf() inside another printf().

2 Answers  


int i; main(){ int t; for ( t=4;scanf("%d",&i)-t;printf("%d\n",i)) printf("%d--",t--); } // If the inputs are 0,1,2,3 find the o/p

2 Answers  


find simple interest & compund interest

2 Answers  


Categories