我无法找到对decltype的一个很好的解释.请告诉我,作为一名初学程序员,它的作用以及它为何有用.
例如,我正在读一本提出以下问题的书.有人可以向我解释答案和原因,以及一些好的(初级)例子吗?
当代码完成时,每个变量的类型和每个变量的值是多少?
Run Code Online (Sandbox Code Playgroud)int a = 3, b = 4; decltype(a) c = a; decltype((b)) d = a; ++c; ++d;
逐行解释将非常有帮助.
注意: 我的班主任把这个问题作为一项任务给了我......我没有被要求这样做,但请告诉我如何用递归来做
可以使用Pascal三角形计算二项式系数:
1 n = 0
1 1
1 2 1
1 3 3 1
1 4 6 4 1 n = 4
Run Code Online (Sandbox Code Playgroud)
三角形的每个新级别在末端都有1个; 内部数字是它们上面两个数字的总和.
任务:编写一个包含递归函数的程序,使用Pascal三角形技术生成幂n的二项式系数列表.例如,
输入= 2
输出= 1 2 1
输入= 4
输出=1 4 6 4 1
做到这一点,但告诉我如何使用递归...
#include<stdio.h>
int main()
{
int length,i,j,k;
//Accepting length from user
printf("Enter the length of pascal's triangle : ");
scanf("%d",&length);
//Printing the pascal's triangle
for(i=1;i<=length;i++)
{
for(j=1;j<=length-i;j++)
printf(" ");
for(k=1;k<i;k++)
printf("%d",k);
for(k=i;k>=1;k--)
printf("%d",k);
printf("\n");
}
return 0;
}
Run Code Online (Sandbox Code Playgroud) 问题是
回文是在两个方向上读取相同的字符串,例如,赛车,眼睛等.编写程序,提示用户输入字符串并使用递归函数来确定给定输入是否为回文
到目前为止我已经做到了这一点,但它不是工作的人:
#include<stdio.h>
#include<conio.h>
#include<string.h>// to save string
int isPalindrome(char*str);
int main (void)
{
int result;
char str[50];
printf("\n pls enter string; \n");
gets(str);
result = isPalindrome(str);
if(result ==1)
{
printf("\n input string in a palindrome string ");
}
else
{
printf(" not a palindrome");
}
getch();
return 1;
}
int isPalindrome(char*str)
{
static int length = strlen(str);
if(length<1)
{
return 1;
}
if(str[0]=str[lenght - 1])
{
length-=2;
}
return isPalindrome(str + 1)
}
{
return 0;
}
Run Code Online (Sandbox Code Playgroud)