我13岁并学习c编程,所以我对c编程有一个非常基本的理解。我正在学习如何'显示变量值',我正在使用非常基本的代码,但是当我尝试使用GNU(MinGW)编译它时,它告诉我......
vars.c:4:1:错误:预期的声明说明符或'...'之前的''''令牌
请有人告诉我如何解决这个问题!
这是代码:
#include <stdio.h>
int main(
(printf( "Integer is %d \n",num);
(printf( "Values are %d and %f \n",num,pi);
(printf( "%%7d displays %7d \n",num);
(printf( "%%07d displays %07d \n",num);
(printf( "Pi is approximately %1.10f \n",pi);
(printf( "Right-aligned %20.3f rounded pi \n",pi);
(printf( "Left-aligned %-20.3f rounded pi \n",pi);
return 0 ;)
)
({
int num = 100;
double pi = 3.1415926536;
(return 0 ;)
})
答案 0 :(得分:2)
从第三行开始,您使用的语法几乎完全错误。您从未完成声明main
的参数,并且您有大量额外的括号。您应该谷歌“c hello world”并尝试运行这些示例,以便您可以了解C代码的外观。以下是一个可能有用的示例:
#include<stdio.h>
int main()
{
int num = 100;
printf("Hello World\n");
printf("Integer is %d\n",num);
return 0;
}
答案 1 :(得分:2)
我不确定您在哪里提出此代码,但我假设您打算键入以下内容:
#include <stdio.h>
int main(void)
{
int num = 100;
double pi = 3.1415926536;
printf( "Integer is %d \n",num);
printf( "Values are %d and %f \n",num,pi);
printf( "%%7d displays %7d \n",num);
printf( "%%07d displays %07d \n",num);
printf( "Pi is approximately %1.10f \n",pi);
printf( "Right-aligned %20.3f rounded pi \n",pi);
printf( "Left-aligned %-20.3f rounded pi \n",pi);
return 0 ;
}
尝试找到一个在线C编程教程并逐步完成它。它将比试错更令人满意。
答案 2 :(得分:0)
至少有三个问题:
1)完全不必要的括号
2)未初始化的变量
3)???尝试在main()???
中创建一个lambda建议修改:
#include <stdio.h>
int main() {
int num = 100;
double pi = 3.1415926536;
printf( "Integer is %d \n",num);
printf( "Values are %d and %f \n",num,pi);
return 0 ;
}
答案 3 :(得分:0)
代码的工作版本:
#include <stdio.h>
int main() {
int num = 100;
float pi = 3.1415926536;
printf( "Integer is %d \n",num);
printf( "Values are %d and %f \n",num,pi);
printf( "%%7d displays %7d \n",num);
printf( "%%07d displays %07d \n",num);
printf( "Pi is approximately %1.10f \n",pi);
printf( "Right-aligned %20.3f rounded pi \n",pi);
printf( "Left-aligned %-20.3f rounded pi \n",pi);
return 0;
}