Close
Close

Why can't we define recursive function as a preprocessor ?? See the below example

   Yashack

#include <stdio.h> 
#define factorial(a) (a==1?1:a*factorial(a-1))
    
    int main() 
    { 
        int n; 
        printf("Enter number\n"); 
        scanf("%d", &n); 
        int fact = factorial(n)    
        
         printf("Factorial is %d ",fact); 
        
            return 0; 
}

 


Answers

  •   

    Macros are pre-processor i.e., they are processed before compilation and are not compiled. So, it can’t be recursive because it factorial(n) is replaced just once during the recursion.



Ask Yours
Post Yours
Write your answer