You are here:

C/swapping of two variables

Advertisement


Question
FIRST PROGRAM:
void main()
{
int a=10,b=26;
a=1?a-(b=1?((a=1?a+b:0)-b):0):0;
printf("a=%d\nb=%d",a,b);
}
OUTPUT:a=26;b=10
NOTE:For this same program i am not get answer when i get input using scanf statements.What is the reason behind this?
 If you are willing please answer for this question and write to my mail sir.

Answer
I don't know how you used the scanf().
I too tried to use scanf() and the program is working fine.
Here below is the program with scanf() to read the values and also I have attached the o/p that I got from this program.
void main()
{
int a=0, b=0;
printf("Enter the value of a & b: ");
scanf("%d %d", &a, &b);
a=1?a-(b=1?((a=1?a+b:0)-b):0):0;
printf("a=%d\nb=%d\n",a,b);
}
linei-sb100:temp> ./a.out
Enter the value of a & b: 11 25
a=25
b=11
linei-sb100:temp> ./a.out
Enter the value of a & b: 67 22
a=22
b=67
linei-sb100:temp>

C

All Answers


Answers by Expert:


Ask Experts

Volunteer


Narendra

Expertise

I can answer questions in C related to programming, data structures, pointers and file manipulation. I use Solaris for doing C code and if you have questions related to C programming on Solaris, I will be able to help better.

Experience

6.5

Organizations belong to
Sun Microsystems

Awards and Honors
Brain Bench Certified Expert C programmer.
Advanced System Software Certified

©2012 About.com, a part of The New York Times Company. All rights reserved.