473,387 Members | 1,504 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

query in reccursion

int giValue = 5; /* Global Variable Declaration */
void fnReverse()
{
if (giValue 0) {
giValue--;
fnReverse();
}
printf("%d\n",giValue);
}

/
************************************************** ************************************************** ********
* why the answer is 0 six times????????????????

************************************************** ************************************************** ******/
Dec 11 '07 #1
3 1117
bn*******@gmail.com wrote:
int giValue = 5; /* Global Variable Declaration */
void fnReverse()
{
if (giValue 0) {
giValue--;
fnReverse();
}
printf("%d\n",giValue);
}

/
************************************************** ************************************************** ********
* why the answer is 0 six times????????????????

************************************************** ************************************************** ******/
"Six times" because the values 5,4,3,2,1,0 are a set
of cardinality six.

"0" because giValue is equal to zero at each of the
six executions of the printf call.

--
Eric Sosman
es*****@ieee-dot-org.invalid
Dec 11 '07 #2
bn*******@gmail.com wrote:
int giValue = 5; /* Global Variable Declaration */
void fnReverse()
{
if (giValue 0) {
giValue--;
fnReverse();
}
printf("%d\n",giValue);
}

/
************************************************** ************************************************** ********
* why the answer is 0 six times????????????????

************************************************** ************************************************** ******/
Because you hit the printf statement 6 times for this loop. Consider this, if
giValue was initialized to zero you would still print it's value once.

Dec 11 '07 #3
bn*******@gmail.com wrote:
int giValue = 5; /* Global Variable Declaration */
void fnReverse()
{
if (giValue 0) {
giValue--;
fnReverse();
}
printf("%d\n",giValue);
}

/
************************************************** ************************************************** ********
* why the answer is 0 six times????????????????

************************************************** ************************************************** ******/
Because you print the value of `giValue` after the recursion has been
all the way down to the bottom.

As would have been obvious if you'd tried "play machine" or attempted the
induction -- two techniques that I'd advise adding to your kit.

--
Chris "once a formalist, always (but not only) a formalist" Dollin

Hewlett-Packard Limited registered office: Cain Road, Bracknell,
registered no: 690597 England Berks RG12 1HN

Dec 11 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: jaysonsch | last post by:
Hello! I am having some problems with a database query that I am trying to do. I am trying to develop a way to search a database for an entry and then edit the existing values. Upon submit, the...
29
by: shank | last post by:
1) I'm getting this error: Syntax error (missing operator) in query expression on the below statement. Can I get some advice. 2) I searched ASPFAQ and came up blank. Where can find the "rules"...
9
by: netpurpose | last post by:
I need to extract data from this table to find the lowest prices of each product as of today. The product will be listed/grouped by the name only, discarding the product code - I use...
3
by: Harvey | last post by:
Hi, I try to write an asp query form that lets client search any text-string and display all pages in my web server that contain the text. I have IIS 6.0 on a server 2003. The MSDN site says...
4
by: Diamondback | last post by:
I have two tables, WIDGETS and VERSIONS. The WIDGETS table has descriptive information about the widgets while the VERSIONS table contains IDs relating to different iterations of those widgets...
14
by: Dave Thomas | last post by:
If I have a table set up like this: Name | VARCHAR Email | VARCHAR Age | TINYINT | NULL (Default: NULL) And I want the user to enter his or her name, email, and age - but AGE is optional. ...
2
by: Dom | last post by:
I need to run a query based on a query in Access. The second query has a number of conditions which all work well, but there is one more contition I need to set to make it run properly. the...
5
by: Ryan Hubbard | last post by:
Is it possible to get the recordset from an open query window? So you run the query. The window is open. Can vba retrieve this data?
0
by: starace | last post by:
I have designed a form that has 5 different list boxes where the selections within each are used as criteria in building a dynamic query. Some boxes are set for multiple selections but these list...
1
by: vaisali | last post by:
fibonnaci series using reccursion pls give me d code in C
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.