许久之前,就想看看C和C++,看看这两种神奇的编程语言,但是一直被这样或者那样的琐事给耽搁了(狂喷自己的拖延症)。

今天翻开自己的移动硬盘找到一本古老的书籍:《The C Programming Language 中文版》,浏览一下,缓解一下内心的空虚。

事情并没有想象中的那么顺利,刚看了一个例子的两种方法,但是当把他们组合起来时,就遇到了困难:

错误提示:

  error C2143: syntax error : missing ';' before 'type'

  error C2065: 'fahrr' : undeclared identifier

代码如下:(hello.c)

 #include <stdio.h>
main()
{
float fahr, celsius;
float lower, upper, step; lower = ; /* 温度表的下限*/
upper = ; /* 温度表的上限*/
step = ; /* 步长*/ fahr = lower;
while (fahr <= upper) {
celsius = 5.0 * (fahr-32.0) / 9.0;
printf("%3.0f %6.1f\n", fahr, celsius);
fahr = fahr + step;
} int fahrr; for (fahrr=;fahrr<=;fahrr=fahrr+)
{
printf("%3d %6.1f\n",fahrr,(5.0/9.0)*(fahrr-));
}
printf("Press ENTER to continue...");
}

错误出现在18和20行;

但是如果以第18行分开上面和下面都是可以执行的;

一番百度之后:

1.有人说:这段代码在 VC++ 和 DEV C++ 下调试是通过的,自己试了一下,发现在VC++下并没有通过;

2.有人说:用的是C语言环境,要把变量定义放到前面,改了一下:

 #include <stdio.h>
main()
{
float fahr, celsius;
float lower, upper, step; int fahrr; //修改的部分 lower = ; /* 温度表的下限*/
upper = ; /* 温度表的上限*/
step = ; /* 步长*/ fahr = lower;
while (fahr <= upper) {
celsius = 5.0 * (fahr-32.0) / 9.0;
printf("%3.0f %6.1f\n", fahr, celsius);
fahr = fahr + step;
} //int fahrr; //修改的部分 for (fahrr=;fahrr<=;fahrr=fahrr+)
{
printf("%3d %6.1f\n",fahrr,(5.0/9.0)*(fahrr-));
}
printf("Press ENTER to continue...");
}

结果正常通过。

在网上看了一番之后,得出结论:

  在纯C中,在一个代码块中变量声明必须在最前面。

error C2143: syntax error : missing ';' before 'type'的更多相关文章

  1. VC++中编译C出错:error C2143: syntax error : missing ';' before 'type'

    转摘自:http://preceo.blog.51cto.com/6225017/1130931 近来写程序时发现了一个问题,用 VC 编译 C语言是 总是提示一个错误:error C2143: sy ...

  2. error C2143: syntax error : missing ';' before '}'

    今天弄Tab控件,干了一件非常愚蠢的事,没有去声明头文件.这也是今天要记录的问题,提示如下各种 前面一个符号是错误的.如果初学者遇到,算作一个提示,记得声明新类的.h 头文件 标签空间再进一步.cpp ...

  3. LINK : fatal error LNK1117: syntax error in option 'VERSION:1.6.5'

    今天在用vs2015编译ogre 1.6.5的代码时发生连接错误 LINK : fatal error LNK1117: syntax error in option 'VERSION:1.6.5'. ...

  4. Keil C51编译报错error C141: syntax error

    错误代码: typedef unsigned char uchar uchar KeyRowColumnScan() { GPIO_KEY = 0x0f; uchar key_value = ; // ...

  5. CaffeMFC:caffe.pb.h(2525): error C2059: syntax error : 'constant'

    下边的语句会报 syntax error : 'constant'. static const DimCheckMode STRICT = V1LayerParameter_DimCheckMode_ ...

  6. C++ 编译发现 error C2146: syntax error : missing ';' before identifier 'm_ctrlserver'

    解决这个问题的根源是重复包含了头文件

  7. error C2061: syntax error : identifier '__RPC__out_xcount_part'

    朋友遇到的 把dx, windows sdk ,vs2010照着成功人士的配置好 应该就可以了

  8. Syntax error missing ; before *

      [问题] I have a header file like so: #pragma once #include "gamestate.h" #include "Ex ...

  9. C++编译错误syntax error : identifier 'THIS_FILE' 解决方法

    你到代码里搜索 THIS_FILE看是不是它定义在别的头文件前面了,如果是,把它们的头文件紧跟到Stdafx.h后面 我遇到过这问题,这样搞定的 今天遇到个编译错误:..\vc98\include\n ...

随机推荐

  1. Bootstrap(10) 进度条媒体对象和 Well 组件

    一.Well 组件这个组件可以实现简单的嵌入效果. <!-- //嵌入效果 --> <div class="well">Bootstrap</div& ...

  2. pycharm 配置支持vue

    http://www.cnblogs.com/c-x-m/p/9229199.html

  3. vue 动态修改el-upload 的action

    action是一个必填参数,且其类型为string,我们把action写成:action,然后后面跟着一个方法名,调用方法,返回你想要的地址,代码示例: //html 代码 <el-upload ...

  4. 大数乘法java版

    import java.util.*; import java.math.*; public class NumMul{ public static void main(String args[]){ ...

  5. 文档根元素 "mapper" 必须匹配 DOCTYPE 根 "configuration"

    该问题是因为xml的头部写错了,一个是configuration,一个是mapper,不能直接复制. 参考链接:http://blog.csdn.net/testcs_dn/article/detai ...

  6. php中static静态关键字的使用方法和应用场景

    php中除了常规类和方法的使用,访问控制之外,还有静态关键字static,静态变量可以是局部变量也可以是全局变量,当一个程序段执行完毕时,静态变量并没有消失,它依然存在于内存中,下次在定义时还是以前的 ...

  7. Eclipse新建tld文件

    tld(tag lib description文件)就是以.tld结尾的XML文件 选好目录右键 --> New --> Other -->找到XML FIle --> Nex ...

  8. Web 文件上传方面的安全问题

    一. 文件上传漏洞与WebShell的关系 文件上传漏洞是指网络攻击者上传了一个可执行的文件到服务器并执行.这里上传的文件可以是木马,病毒,恶意脚本或者WebShell等.这种攻击方式是最为直接和有效 ...

  9. YII配置mysql读写分离

    Mysql 读写分离 YIi 配置 <?php return [ 'class' => 'yii\db\Connection', 'masterConfig' => [ // 'ds ...

  10. office 2007,SQL Server 2008,VS2010安装步骤

    office 2007,SQL Server 2008,VS2010的安装顺序是不是office 2007,SQL Server 2008,VS2010呢? 前几天先安装了SQL Server 200 ...