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

Is there any difference between the two declarations, 1. int foo(int *arr[]) and 2. int foo(int *arr[2])

1 Answers  


main() { if ((1||0) && (0||1)) { printf("OK I am done."); } else { printf("OK I am gone."); } } a. OK I am done b. OK I am gone c. compile error d. none of the above

5 Answers   HCL,


write a c program to Create a registration form application by taking the details like username, address, phone number, email along with password and confirm password (should be same as password).Ensure that the password is of 8 characters with only numbers and alphabets. Take such details for 5 users and display the details. In place of password display “****”. (Use Structures).

0 Answers   CDAC, College School Exams Tests,


write a c-program to display the time using FOR loop

3 Answers   HCL,


Is the following code legal? void main() { typedef struct a aType; aType someVariable; struct a { int x; aType *b; }; }

1 Answers  






main() { int i; clrscr(); printf("%d", &i)+1; scanf("%d", i)-1; } a. Runtime error. b. Runtime error. Access violation. c. Compile error. Illegal syntax d. None of the above

1 Answers   HCL,


main() { int i = 3; for (;i++=0;) printf(“%d”,i); }

1 Answers   CSC,


Declare an array of N pointers to functions returning pointers to functions returning pointers to characters?

1 Answers  


how can i cast a char type array to an int type array

2 Answers  


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

11 Answers  


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; }

2 Answers  


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().

1 Answers  


Categories