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 |
main() { float me = 1.1; double you = 1.1; if(me==you) printf("I love U"); else printf("I hate U"); }
main() { char i=0; for(;i>=0;i++) ; printf("%d\n",i); }
Write a C program to add two numbers before the main function is called.
why is printf("%d %d %d",i++,--i,i--);
#include <stdio.h> int main(void) { int a=4, b=2; a=b<<a+b>>2 ; printf("%d",a); return 0; }
void main() { int i; char a[]="\0"; if(printf("%s\n",a)) printf("Ok here \n"); else printf("Forget it\n"); }
#ifdef something int some=0; #endif main() { int thing = 0; printf("%d %d\n", some ,thing); }
how to concatenate the two strings
how to delete an element in an array
write a program to count the number the same (letter/character foreg: 's') in a given sentence.
main() { int i=0; for(;i++;printf("%d",i)) ; printf("%d",i); }
how can i cast a char type array to an int type array