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.

Akshay said:   1 decade ago
@Jigar is correct. Store result in address of i i.e. at *j.

Therefore *j=s;

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

*j = s means store the s value.

Akshay k said:   1 decade ago
@Rahul - s**j means multiply s with *j. You can see this as s*(*j).

Gowthami said:   1 decade ago
Can you give a brief explanation for this question sir.

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

Jas said:   1 decade ago
Since A, C, D are wrong ANS. Therefore B is correct.

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

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

Devansh said:   7 years ago
How come 120? Please anyone explain.

RATHOD said:   9 years ago
Please anyone explain it properly.


Post your comments here:

Your comments will be displayed after verification.