Flash Website Builder- Trendy Site Builder is a Flash Site Building tool that helps users build stunning websites. Check Out Custom Custom Logo Design by LogoBee. Website Design and Free Logo Templates available.
 CodingForums.com Simple c program-please explain output.

Before you post, read our: Rules & Posting Guidelines

Enjoy an ad free experience by logging in. Not a member yet? Register.
 09-13-2012, 11:37 AM PM User | #1 hitesh.incept New to the CF scene   Join Date: Sep 2012 Posts: 1 Thanks: 0 Thanked 0 Times in 0 Posts Simple c program-please explain output. Code: ```int main() { int a=7, t=0; t=--a+--a+a+++a; printf("%d",t); }``` output: 20 I could not understand why it prints '20' ? please explain it ! Last edited by hitesh.incept; 09-13-2012 at 11:43 AM..
 09-26-2012, 07:03 AM PM User | #2 DELOCH Regular Coder     Join Date: Apr 2006 Location: Canada Posts: 537 Thanks: 4 Thanked 2 Times in 2 Posts a=7 t=(--a)+(--a)+(a++)+a; =6 + 6 + 0 + 8 = 20 a++ becomes 0 in that situation for some reason which I do not understand Last edited by DELOCH; 09-26-2012 at 07:32 AM..
 10-03-2012, 05:01 AM PM User | #3 slickuser New to the CF scene   Join Date: Oct 2012 Posts: 9 Thanks: 0 Thanked 4 Times in 4 Posts I believe the pre-decrement (or increment) will happen entirely before the final calculation. The post-increment (or decrement) will happen after the calculation. Thus: a=7; two decrements happen first and a=5 and the increment happens after the calculation; so: 5 + 5 + 5 + 5 = 20. The value of 'a' after the calculation is a=6. If you instead did: t=--a+--a+a+++a+++a; the value of t=25 (5+5+5+5+5) and a=7.
 10-20-2012, 07:50 AM PM User | #4 rileyvanzeeland New to the CF scene   Join Date: Oct 2012 Posts: 2 Thanks: 0 Thanked 0 Times in 0 Posts You are essentially doing this- Code: ```int main() { int a=7, t=0; --a; --a; t=a; t+=a; t+=a; t+=a; a++; printf("%d",t); }```

 Bookmarks

 Thread Tools Rate This Thread Rate This Thread: 5 : Excellent 4 : Good 3 : Average 2 : Bad 1 : Terrible

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is Off Forum Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home :: Client side development     JavaScript programming         DOM and JSON scripting         Ajax and Design         JavaScript frameworks         Post a JavaScript     HTML & CSS     XML     Flash & ActionScript         Adobe Flex     Graphics and Multimedia discussions     General web building         Site reviews         Building for mobile devices :: Server side development     Apache configuration     Perl/ CGI     PHP         Post a PHP snippet     MySQL         Other Databases     Ruby & Ruby On Rails     ASP     ASP.NET     Java and JSP     Other server side languages/ issues         ColdFusion         Python :: Computing & Sciences     Computer Programming     Computer/PC discussions     Geek News and Humour Web Projects and Services Marketplace     Web Projects         Small projects (quick fixes and changes)         Medium projects (new script, new features, etc)         Large Projects (new web application, complex features etc)         Unknown sized projects (request quote)         Vacant job positions         Looking for work/ for hire         Project collaboration/ partnership         Paid work offers and requests (Now CLOSED)     Career, job, and business ideas or advice     Domains, Sites, and Designs for sale         Domains for sale         Websites for sale         Design templates and graphics for sale :: Other forums     Member Offers     Forum feedback and announcements

All times are GMT +1. The time now is 12:03 AM.