> -----Original Message----- > From: civics@oocities.com [mailto:civics@oocities.com] > Sent: Wednesday, May 23, 2007 7:39 PM > To: vijay.zanvar@wipro.com > Subject: Survey Results > > Name = sathish > URL = sathish58@yahoo.com > Comments = Hi Vijay > > This is sathish. I used to read C Tips and Tricks. I have > many questions out of which I am sending only 3 to you and I > hope you will reply > > 1) Why the below program says LValue required? > > main() > { > int a=5; > int b=4; > int c; > a > b ? c=1 : c = 0; > } To understand why you are getting the "LValue required" error, you should have knowledge of how the conditional statement is defined by the C grammar. I assume you know interpreting the grammar. So, conditional-expression: logical-OR-expression logical-OR-expression ? expression : conditional-expression As you see, the operands of the ?: operator, in order, are a logical expression, an expression, and either another expression or a nested conditional expression. Two examples are shown below: a > b ? a : b; and a > b ? a : (b > c ? b : c); Now, compare your conditional expression with the grammar. You will find that you have used statements (c = 1 and c = 0) instead of expression. What actually you want is: c = a > b ? 1 : 0; > > But when I say (c=0) it accepts. > (c=0) is an expression, not a statement. > 2) I am little bit confused or rather I dont know whats > actually happening in this program. The following program > seems to be fine but did not give required output. > > > #include<stdio.h> > > #define TOTAL_ELEMENTS (sizeof(array) / sizeof(array[0])) > > int array[] = {23,34,12,17,204,99,16}; > int main() > { > int d; > for(d=-1;d <= (TOTAL_ELEMENTS-2);d++) > printf("%d\n",array[d+1]); > return 0; > } > Incidently, this problem is discussed in the Q. 29 in http://www.oocities.org/vijoeyz/faq/. > 3) How can I substitute the condition here so that I can > print both "Hello" and "World" > > if "condition" > printf("Hello"); > else > printf("World"); > > { ... if (0) { hello: printf("Hello"); goto world; } else { goto hello; world: printf("world"); } ... } Using goto is not always recommended. One situaion where they are used is, if you are in deeply nested for loop and you want get out of it. > The above may sound silly for you but as a beginner I wonder > how the above things are going on. Thank you once again. > > Bye for now > > Thanks & Regards > Sathish Kumar > subject = Survey Results > REMOTE_HOST: 216.119.215.193 >