关于C语言函数注释的一个技巧
在C语言函数中,我们一般需要对函数参数进行必要的说明,这样我们可以更快的了解这个函数的功能。
#include <stdio.h>
void print(int a,/*hhhh*/
int b
);
int main() {
print(1,2);
}
void print(int a, //这是一个注释
int b //这是一个注释
)
{
printf("hello world\n");
}
比如这个代码,我们可以这样对函数参数进行说明。
当然我们也可以用 /**/来注释
另外要注意函数参数后括号要另起一行,
#include <stdio.h>
void print(int a,/*hhhh*/
int b
);
int main() {
print(1,2);
}
void print(int a, //这是一个注释
int b //这是一个注释 )
{
printf("hello world\n");
}
如果下成这样,那么会报错,因为//会把后面一整行都注释掉,所以后括号也被注释掉了。
但是用/**/替代//却可以
#include <stdio.h>
void print(int a,/*hhhh*/
int b
);
int main() {
print(1,2);
}
void print(int a, //这是一个注释
int b /*这是一个注释*/ )
{
printf("hello world\n");
}
其实综合上面的这些,我们只需要知道
- //是注释掉该行后面的所有内容,因此后括号会被注释掉。
- /**/注释是注释掉夹在中间的内容,因此不会注释掉后括号。
在C语言中只要我们掌握了上面两种方法注释方法,任何函数参数的注释都难不倒我们了。