error
2014-04-07 21:14
225 查看
1.error C2109: subscript requires array or pointer type
追问
回答
根本的问题是全局变量和局部变量重名了 全局变量b[MAX] 局部变量b 默认在函数体里面使用的是局部变量b[i]就出错了 可在前面加:: 表示使用的是全局变量 要不然就改名,使之不重名 2.error LNK2001: unresolved external symbol _main 主函数的main写错了。 3. error: variable-size type declared outside of any function const int MAX=1001; 是c++中的,所以注意加头文件<iostream> c语言中的#define MAX 1001 与C++等现代编程语言不同,传统上的C语言是不支持变长数组功能的,也就是说数组的长度是在编译期就确定下来的,不能在运行期改变。 c++的可变长数组: C99 gives C programmers the ability to use variable length arrays, which are arrays whose sizes are not known until run time. A variable length array declaration is like a fixed array declaration except that the array size is specified by a non-constant expression. When the declaration is encountered, the size expression is evaluated and the array is created with the indicated length, which must be a positive integer. Once created, variable length array cannot change in length. Elements in the array can be accessed up to the allocated length; accessing elements beyond that length results in undefined behavior. There is no check required for such out-of-range accesses. The array is destroyed when the block containing the declaration completes. Each time the block is started, a new array is allocated. 以上就是对变长数组的说明,此外,在文献[1]中作者还说明,变长数组有以下限制: 1、变长数组必须在程序块的范围内定义,不能在文件范围内定义变长数组; 2、变长数组不能用static或者extern修饰; 3、变长数组不能作为结构体或者联合的成员,只能以独立的数组形式存在; 4、变长数组的作用域为块的范围,对应地,变长数组的生存时间为当函数执行流退出变长数组所在块的时候; 4.error C2107: illegal index, indirection not allowed
追问
main() {char a[]="morning",t; int i, j=0; for(i=1;i<7;i++) if(a[j]<a[i]) j=i; t=a[j];a[j]=a[7]; a[7]=a[j]; puts[a]; }求结果
回答
首先是puts[a]错了,应该用括号puts(a);, 还有就是你的意图我不怎么明白,不过你最好还是看看你的if语句吧,没有花括号{ }。 类似这种括号的格式用错了。
相关文章推荐
- 有助于改善性能的技巧(1)
- ToArray()和IEnumerable<T>,List<T>
- LED点阵的基本操作探索
- mac下卸载mysql的方法
- codeforces 414b(数位DP)
- 题目1 : 传话游戏
- opencv批量读图像序列
- 面试-Synchronized和Lock的区别
- 认识Javascript中History对象并用其访问历史记录
- 清明作业
- DB优化简单总结
- HDU - 1422 重温世界杯
- ZOJ 3775 ?(>_o)!
- Origami
- 《Box2D for Flash Games》翻译 在世界里添加刚体(A)
- 学习心得-1
- 产品原型设计工具 Balsamiq Mockups(转)
- ReportStudio入门教程(十三) - 列表的复杂表头之隐藏
- spring4+hibernate4 configlocation出错
- 最近关注的几个算法