6
Contributors
5
Replies
6
Views
10 Years
Discussion Span
Last Post by Duoas
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

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.