The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
.
google unix.com



High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
printf mirusnet Shell Programming and Scripting 4 01-23-2008 10:09 AM
printf question hankooknara Shell Programming and Scripting 3 06-19-2007 01:28 AM
printf and imaxdif_t grumpf High Level Programming 2 09-01-2006 04:03 AM
printf command in ksh cin2000 Shell Programming and Scripting 1 12-21-2005 02:48 PM
Using printf to center CSGUY Shell Programming and Scripting 2 04-19-2005 09:15 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-19-2007
arunviswanath arunviswanath is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 8
Red face printf

What is the output of the following program considering an x86 based parameter passing sequence where stack grows towards lower memory addresses and that arguments are evaluated from right to left:

int i=10;
int f1()
{
static int i = 15;
printf("f1:%d ", i);
return i--;
}
main()
{
int i, j;
i = 5;
printf("%d %d %d", f1(), f1(), i);
}
  #2 (permalink)  
Old 09-19-2007
porter porter is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2007
Posts: 2,965
OKay, I'll bite. I'm not going to run any code.

Firstly the first i=10 is irrelevant, just like the j.

The 1st call to f1() will return 15 and print "f1:15 ".
The 2nd call to f1() will return 14 and print "f1:14 ".

Then you will get "14 15 5", I reckon.
  #3 (permalink)  
Old 09-19-2007
blowtorch's Avatar
blowtorch blowtorch is offline Forum Advisor  
Supporter
  
 

Join Date: Dec 2004
Location: Singapore
Posts: 2,350
This is homework, and even thougt porter has answered, I am still closing this thread. Note that you should be doing your homework yourself and not asking for such direct help over the forums.
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:19 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0