I thought this was algogeeks, not company question geeks. On Aug 7, 4:27 pm, UTKARSH SRIVASTAV <usrivastav...@gmail.com> wrote: > please these questions are compiler dependent and have no standard > answers...........these are rarely asked by companies > > > > > > > > > > On Sun, Aug 7, 2011 at 1:23 PM, Gary Drocella <gdroc...@gmail.com> wrote: > > @puneet The provided faq is garbage, if you want to learn about the > > semantics of the C programming > > language, then refer to this original ISO spec here > >http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1124.pdf > > I also suggest that for all programming languages (OCaml, Ruby, lua > > script, etc) > > > It is definitely not the OS that determines how to execute a given > > fragment of C code, this is the job of the compiler. > > The compiler converts the code into machine code using grammar parsing > > techniques, and the validity of compiling > > C code such as this > > > [CODE] > > int i = 1, j = 3; > > printf("%d", i+++++j); > > [/CODE] > > > will more then likely depend on w/e compiler you're using. If it's a > > good compiler like gcc you can tell the compiler what standard to use. > > gcc -ansi -o foo foo.c > > gcc -c99 -o foo foo.c > > > The only time an OS would do any parsing of code is if you built an > > interpreter such as the JVM on the bare metal of a machine. Benefit > > being > > you have a garbage collector cleaning up un-used memory. The OS is > > more of an abstraction between userspace and the hardware. > > > On Aug 7, 3:22 pm, Puneet Gautam <puneet.nsi...@gmail.com> wrote: > > > Also guys, this link:http://c-faq.com/~scs/cgi-bin/faqcat.cgi?sec=expr > > > > discusses erroneous expns like > > > a[i]=i++; > > > > But if u run this code..this gives no error on GNU compiler.. > > > > So, are we really referring to a reliable document here..? > >http://c-faq.com/~scs/cgi-bin/faqcat.cgi?sec=expr > > > > I really doubt that...! > > > > Run it on as many different systems as you can...! > > > > Lets c what all results we get...!! > > > > Pls give ur feedback... > > > > On 8/8/11, Puneet Gautam <puneet.nsi...@gmail.com> wrote: > > > > > @ Amit: Well, the link you have posted refers that i++*i++ is not an > > > > invalid expression, it just runs differently on different OS's because > > > > every OS has a different implementation on how to solve such > > > > expressions that use the same address space(Address of the integer i). > > > > > As far as i know the value of a variable can be increased multiple > > > > times on most OS's ... i have tried it on TUrbo running on WIN 95 as > > > > well as Dev Cpp on WIN 7 OS. > > > > > Though it may give different output on Unix OS's like Linux but:\ > > > > > Hey, we can only predict the output as we see is apt as far as we > > > > have learnt in books. > > > > > And the output in my first post does the processing the bookish way... > > > > > BUT THE CODE WILL NOT GIVE ANY ERROR ....!!! > > > > > On 8/3/11, Arun <toarunb...@gmail.com> wrote: > > > > >> What Amit told is exactly correct. But I would like to know the > > > >> expression evaluation order of this in gcc and turboc > > > > >> Arun > > > >> On Aug 3, 6:15 pm, Arun Vishwanathan <aaron.nar...@gmail.com> wrote: > > > >>> @amit:+1 > > > > >>> On Wed, Aug 3, 2011 at 3:14 PM, amit karmakar > > > >>> <amit.codenam...@gmail.com>wrote: > > > > >>> > You are wrong. > > > >>> > The above program invokes undefined behavior. Read the standard > > > >>> > language draft to know about sequence points, side effects and > > > >>> > undefined behavior. > > > > >>> > Between a previous and next sequence point a variable's value > > cannot > > > >>> > be modified twice. > > > >>> > c-faq should be quite useful > > > >>> >http://c-faq.com/~scs/cgi-bin/faqcat.cgi?sec=expr > > > >>> > On Aug 3, 5:20 pm, Puneet Gautam <puneet.nsi...@gmail.com> wrote: > > > >>> > > As we know: > > > >>> > > In an expression, if pre n post occur > > > >>> > > simultaneously, pre inc the value then n there only n post > > executes > > > >>> > > it > > > >>> > > after that expression...and expression evaluates right to left... > > > > >>> > > Also, the value of a variable in an expression can be modified > > > >>> > > multifold times...there is no restriction on dat... > > > > >>> > > Here in this code: > > > >>> > > Print statement No.: > > > > >>> > > 1. i++*i++ is equivalent to: > > > >>> > > output i*i(7*7) > > > >>> > > followed by > > > >>> > > i=i+1; > > > >>> > > i=i+1; > > > >>> > > prior to 2nd printf statement..that makes i=9 > > > > >>> > > 2. i++*++i > > > >>> > > expn. evaluates right to left: i inc. by one due to pre.. > > > >>> > > i is now 10 . > > > >>> > > output i*i(10*10) > > > >>> > > i=i+1 (due to post inc., it inc. the value after the output) > > > >>> > > i is now 11 > > > > >>> > > 3. ++i*i++ > > > >>> > > right to left evaluation, but post inc. increases value only > > > >>> > > after > > > >>> > output.. > > > >>> > > coming to ++i in the expn., i inc. to 12 > > > >>> > > output: 12*12 > > > >>> > > i=i+1(due to postinc.) > > > >>> > > i is now 13 > > > > >>> > > 4. ++i*++i > > > >>> > > both pre inc operators, order of evaluation doesnt ,matter: > > > >>> > > i=i+1 > > > >>> > > i=i+1 > > > >>> > > output: 15*15 > > > > >>> > > i finishes at 15 > > > > >>> > > Hence the output: > > > >>> > > 49 > > > >>> > > 100 > > > >>> > > 144 > > > >>> > > 225 > > > > >>> > > I think i made it clear.. > > > >>> > > Feel free to point any loopholes.. > > > > >>> > > Thanks. > > > > >>> > > On 8/3/11, ankit sambyal <ankitsamb...@gmail.com> wrote: > > > > >>> > > > Its compiler dependent. Acc. to the C standard an object's > > stored > > > >>> > > > value > > > >>> > can > > > >>> > > > be modified only once in an expression. > > > > >>> > > > -- > > > >>> > > > You received this message because you are subscribed to the > > Google > > > >>> > Groups > > > >>> > > > "Algorithm Geeks" group. > > > >>> > > > To post to this group, send email to > > algogeeks@googlegroups.com. > > > >>> > > > To unsubscribe from this group, send email to > > > >>> > > > algogeeks+unsubscr...@googlegroups.com. > > > >>> > > > For more options, visit this group at > > > >>> > > >http://groups.google.com/group/algogeeks?hl=en. > > > > >>> > -- > > > >>> > You received this message because you are subscribed to the Google > > > >>> > Groups > > > >>> > "Algorithm Geeks" group. > > > >>> > To post to this group, send email to algogeeks@googlegroups.com. > > > >>> > To unsubscribe from this group, send email to > > > >>> > algogeeks+unsubscr...@googlegroups.com. > > > >>> > For more options, visit this group at > > > >>> >http://groups.google.com/group/algogeeks?hl=en. > > > > >> -- > > > >> You received this message because you are subscribed to the Google > > Groups > > > >> "Algorithm Geeks" group. > > > >> To post to this group, send email to algogeeks@googlegroups.com. > > > >> To unsubscribe from this group, send email to > > > >> algogeeks+unsubscr...@googlegroups.com. > > > >> For more options, visit this group at > > > >>http://groups.google.com/group/algogeeks?hl=en. > > > -- > > You received this message because you are subscribed to the Google Groups > > "Algorithm Geeks" group. > > To post to this group, send email to algogeeks@googlegroups.com. > > To unsubscribe from this group, send email to > > algogeeks+unsubscr...@googlegroups.com. > > For more options, visit this group at > >http://groups.google.com/group/algogeeks?hl=en. > > -- > *UTKARSH SRIVASTAV > CSE-3 > B-Tech 3rd Year > @MNNIT ALLAHABAD*
-- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.