• error


       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语句吧,没有花括号{ }。
    类似这种括号的格式用错了。
  • 相关阅读:
    CSS边框
    各大网站注册的用处(个人看法)
    20121011 外边距
    20120921碎碎念
    20121011 CSS一
    20120919碎碎念
    CSS 文本装饰属性
    外边距合并
    EverBox开发笔记1
    “Core Data”中的“dynamic implementation”
  • 原文地址:https://www.cnblogs.com/money-lady/p/error.html
Copyright © 2020-2023  润新知