| |
Welcome to our Queries archive!
|
Queries |
Who
had it |
|
Q: How do I take in unlimited
arguments in a function's argument? |
George Allen |
|
Ans: Use the stdarg.h header file.
Have a look at its help to understand its use. |
|
Q: Can you tell me what is recursion?
Please give a simple example. |
Prakash
(prakashk@cyberspace.org) |
Ans: Well, recursion is a concept in
C++ in which you call a function which calls the calling function. This
would normally result in an infinite loop, hence some condition to break
the loop is always there.
Here is an example:
...
int rec(int x);
void main()
{
int a, fact;
cout<<"Enter any number : ";
cin>>a;
fact=rec(a);
cout<<"Factorial of "<<a<<" = "<<fact;
}
int rec(int x)
{
int f;
if(x==1)
return 1;
else
f=x*rec(x-1);
return f;
}
... |
| |
[
Click here to ask a
question
]
|
|