C aptitude question
Can anyone tell me how the following code results...
#include
int main()
{
int a=1,b=1,c;
c=a=0? (a=1)😔b=2);
printf("%d %d %d",a,b,c);
getch();
return 0;
}
Results as 2 2 2
clarify me how the variables a , b , c holds the value 2?
#include
int main()
{
int a=1,b=1,c;
c=a=0? (a=1)😔b=2);
printf("%d %d %d",a,b,c);
getch();
return 0;
}
Results as 2 2 2
clarify me how the variables a , b , c holds the value 2?
Replies
-
nareshkumar6539yes answer is 2 2 2
assignment operator is right associative
c=a=0? (a=1)😔b=2); will be divided into two parts
so first of all
a=0?(a=1)😔b=2); will be executed in that statement first a=1 and b=2 will be assigned.
In conditional operator if condition is true first part will be executed otherwise second part will be executed
0 means it is false so b value will be assigned to a.now a contains 2, after that next assignement will be take plase i.e c value will be replaced by a value i.e now c also contains 2. -
Nikumbh@nareshkumar653 thanks a lot... 😀
You are reading an archived discussion.
Related Posts
Introduction
Date: 20/06/2012
Have you wondered about designing your website or making one just for fun or for a learning experience? This multipart tutorial will teach you the basics of...
Hello friends,
I am EC diploma holder .... I wanna know which programming languages wud help me in studies.plz mention all.
Also, what's skada ?? plz gimme more detail abt...
Hii friends, which programming languages should i master before getting into "Android apps developing".
Good day fellas,
I am estongski ,an electrical engineering graduate from the Philippines. I have more questions than answers that pertains to electrical engineering because i was not able to...
hello all,
iam 3rd year btech ece student.I need to present a seminar as a part of my academics. I am looking for the seminar topic which holds the current...