I scribble some typical C codes here which I find usually while programming. Blog comprises of C programming questionnaires where you have to identify the output, identical to questions asked in interviews. Any corrections or suggestions are welcomed.
Note: Some questions may lack explanation, in such case apt explanations are invited & welcomed!
Friday, September 9, 2011
Coding Puzzle No. 7?
#include<stdio.h>
void main() { int a=5,b=2; a^=b^=a^=b;
printf("%d %d",a,b); }
Output:
2 5
ConCept:
This is a simple integer swapping program using XOR. If we expand the step, it will result into --
a = a^b;
b = a^b;
a = a^b;
No comments:
Post a Comment