小编Mei*_*Mei的帖子

为什么c ++模板参数应该声明为类类型?

功能模板的语法

template <**class** T, ...>
    returntype functionname(arguments)
    {
           .....
           .....
     }
Run Code Online (Sandbox Code Playgroud)

我有两个问题?

  1. 为什么模板参数应该声明为类类型?(即使用class关键字)
  2. 当我们将它声明为类类型时,编译器会做什么?

c++ syntax templates language-lawyer

4
推荐指数
1
解决办法
192
查看次数

因子程序c使用带有while循环的C中的递归函数

使用while循环在c中使用递归的因子程序.在该程序中,一旦执行到达函数return语句,它就不会返回到函数调用.相反,它重复执行该功能.任何人都可以告诉我这个程序有什么问题.

#include<stdio.h>    
int fact(int n)
{    
    int x=1;    

    while(n>1)    
    {    
        x=n*fact(n-1);    
    }    

    return(x);    
}    

void main()    
{    
    int n,fact1;    
    scanf("%d",&n);    
    fact1=fact(n);    
    printf("%d",fact1);    
}
Run Code Online (Sandbox Code Playgroud)

c recursion factorial

2
推荐指数
2
解决办法
6万
查看次数

标签 统计

c ×1

c++ ×1

factorial ×1

language-lawyer ×1

recursion ×1

syntax ×1

templates ×1