dimanche 12 juillet 2020

How is the output correct?

code

in case if the image not visible.

#include <stdio.h>
int fun(int n)
{
    if(n=4)
    return n;
    else return 2*fun(n+1);
}
int main()
{
    printf("%d",fun(2));
}

This is the code snippet and the output is given as 4 by the professor.

How is the output correct? Is it possible that n=4 is assigned in the 'if-else' statement as the assignment operator is correct,but the "if" condition will not work as the syntax is wrong and the output will be directly given as 4.

Aucun commentaire:

Enregistrer un commentaire