C Programming - Pointers - Discussion

Discussion Forum : Pointers - Point Out Correct Statements (Q.No. 8)
8.
In the following program add a statement in the function fact() such that the factorial gets stored in j.
#include<stdio.h>
void fact(int*);

int main()
{
    int i=5;
    fact(&i);
    printf("%d\n", i);
    return 0;
}
void fact(int *j)
{
    static int s=1;
    if(*j!=0)
    {
        s = s**j;
        *j = *j-1;
        fact(j);
        /* Add a statement here */
    }
}
j=s;
*j=s;
*j=&s;
&j=s;
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
28 comments Page 2 of 3.

Supraja said:   9 years ago
What an excellent answer @Jas. Well said.

Zhattuchand Hapshete said:   9 years ago
You are a genius, your explanation is satisfied @Tomas.

Shivu said:   9 years ago
Thanks @R K.

Tomas said:   9 years ago
Everything's more or less good, except that the factorial will be stored in i. After function call j will be destroyed.
(1)

Sahil said:   1 decade ago
The answer won't be 120 since s is static.

The answer will always be 0 you can copy this code in your compiler.

RamRatan kumar said:   1 decade ago
Why can I store the address of s in j? I also access the value of s through j because it store the address of s;

R K said:   1 decade ago
*j = &s means store the s address.

*j = s means store the s value.

Swathi said:   1 decade ago
Please explain difference between *j=&s, *j=s.

Theettam said:   1 decade ago
@Udam: Same doubt here! Also, after each return from recursion, that value of s in the stack shall be copied to *j right?

Udam said:   1 decade ago
Why j=&s is not workings?


Post your comments here:

Your comments will be displayed after verification.