6
Contributors
5
Replies
6
Views
9 Years
Discussion Span
Last Post by Duoas
0

do what without swap function? Stop the nonsense and try...also....post proper/complete questions.

1

without using swap function....

I am going to say this as nice as I feel like.
Stop bombing the C forum with trivial questions.
You are just going to annoy everyone around here.
Do some "work of your own first". Search the forum. Show some initiative.

Votes + Comments
Yes, he is an annoying spammer
0
#include <stdio.h>

int main()
{
	int a=2, b=3, temp;
	
	printf("a: %d, b: %d\n", a, b);
	(temp = a) && (a = b) && (b = temp); 
	
	printf("a: %d, b: %d\n", a, b);
	
	return 0;
	
}

is this what you are looking for?

0

He probably wants this
http://c-faq.com/expr/xorswapexpr.html

Which is of course broken and pointless, yet some people still think it is somehow relevant to the modern world of programming in high level languages. It was nothing more than a neat trick you could pull off in assembler.

0

As long as you keep the sequence points intact and the two values are the same ordinal type then you can do it just fine: a ^= b, b ^= a, a ^= b; Remember though, the result of this expression is the final value of a.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.