Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在c语言中是否可以使用不带变量的文字?_C_Variables_Literals - Fatal编程技术网

在c语言中是否可以使用不带变量的文字?

在c语言中是否可以使用不带变量的文字?,c,variables,literals,C,Variables,Literals,这个问题有点奇怪 出于好奇,是否可以在C中使用不带变量赋值的文本 一般来说,我们喜欢如下: #include<stdio.h> int main() { // Here we are using the literal '7' and assigning it to variable 'a' which will hold it in some address space int a = 7; printf("Hello : %d\n",a); return 0; } 那

这个问题有点奇怪

出于好奇,是否可以在C中使用不带变量赋值的文本

一般来说,我们喜欢如下:

#include<stdio.h>
int main()
{
 // Here we are using the literal '7' and assigning it to variable 'a'  which will hold it in some address space
 int a = 7;
 printf("Hello : %d\n",a);
 return 0;
}
那么,可以使用没有变量的文本吗


提前谢谢。

如果你是说这样的话:

printf("Hello : %d\n", 7);

那么是的,很好。

那么您甚至不需要%d

printfHello:7\n


是的,它们一直被用作返回语句、常量等,即使在printf语句中,%d也是int或integer的占位符,即始终可以用7替换a,但是这种定义常量的方法很受欢迎,就好像您将在代码中多次使用某个数字一样,例如,在数学程序中pi=3.14,它的值只需在一个地方编辑,变量命名提供了一个更简单的参考系统,因此更为常见。

您是否注意到您在返回0中使用的是没有变量赋值的文本;行?更不用说printf语句中的格式字符串了…谢谢Barnar。成功了。谢谢你的快速回复