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
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 |
struct point { int x; int y; }; struct point origin,*pp; main() { pp=&origin; printf("origin is(%d%d)\n",(*pp).x,(*pp).y); printf("origin is (%d%d)\n",pp->x,pp->y); }
main() { int i =10, j = 20; clrscr(); printf("%d, %d, ", j-- , --i); printf("%d, %d ", j++ , ++i); } a. 20, 10, 20, 10 b. 20, 9, 20, 10 c. 20, 9, 19, 10 d. 19, 9, 20, 10
how to swap 3 nos without using temporary variable
What is "far" and "near" pointers in "c"...?
write the function. if all the character in string B appear in string A, return true, otherwise return false.
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; }
write a program to find out roots of quadratic equation "x=-b+-(b^2-4ac0^-1/2/2a"
All the combinations of prime numbers whose sum gives 32
#define assert(cond) if(!(cond)) \ (fprintf(stderr, "assertion failed: %s, file %s, line %d \n",#cond,\ __FILE__,__LINE__), abort()) void main() { int i = 10; if(i==0) assert(i < 100); else printf("This statement becomes else for if in assert macro"); }
main() { int i; float *pf; pf = (float *)&i; *pf = 100.00; printf("\n %d", i); } a. Runtime error. b. 100 c. Some Integer not 100 d. None of the above
‎#define good bad main() { int good=1; int bad=0; printf ("good is:%d",good); }
#include<stdio.h> main() { register i=5; char j[]= "hello"; printf("%s %d",j,i); }