without using swap function....

WaltP commented: Stop spamming the board with stupid questions -2

Recommended Answers

All 5 Replies

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

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.

commented: Yes, he is an annoying spammer +13
#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?

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.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.