指针符号和数组
Pointer Notation and Array
(c )我的程序应该使用户进入输入号,以确定数组的大小以及其元素的大小。然后,我需要按顺序排列元素。我的问题是,每当我运行程序并显示排序的数字时;相反,它显示地址(如果我正确)。
#include <iostream>
using namespace std;
int main()
{
int size;
int i,x,tempVar;
cout << "Enter how many students took the test: ";
cin >> size;
int *myArray = new int [size];
for ( i = 0; i < size; i++)
{
cout << "Enter a score: ";
cin >> myArray[size];
}
for ( i = 0; i < size; i++)
{
for ( x = 0; x < size; x++)
{
if (myArray[i] < myArray[x])
{
tempVar = myArray[i];
myArray[i] = myArray[x];
myArray[x] = tempVar;
}
}
}
cout << "The scores have been sorted out in an ascending ordern";
for (i = 0; i < size; i++)
{
cout << *(myArray + i) << endl;
}
delete [] myArray;
}
它没有显示地址;由于您有:
,它可能显示出垃圾值cin >> myArray[size];
而不是
cin >> myArray[i];
相关文章:
- 使用无符号字符数组有效存储内存
- 检查TCHAR数组输入是否为带符号整数C++
- 如何将字节数组元素替换为修改的十六进制 ASCII 符号?
- 无法在 Arduino 中uint8_t数组转换为无符号长整型数组
- 将无符号字符的向量存储在数组中会给我 std::bad_alloc
- 寻找一种更好的方法来表示无符号字符数组
- 将浮点数转换为无符号字符数组并打印出来
- 在函数中返回无符号字符数组,但不返回指针
- 如何在 C/C++ 中将无符号字符*转换为无符号字符数组?
- 如何返回实际值(在我的例子中是无符号字符数组)而不是来自 C++ 函数的指针?
- 字符数组到无符号字符 *
- 将字符串转换为无符号字符数组/字节数组
- 如何将字符串转换为无符号字符数组
- 在Arduino中将字符串转换为(逗号分隔的十六进制)字符串到无符号字符数组
- 如何从字符数组(不是字符串数组)中删除符号
- 将'\x00\x00\x00'格式的字符串转换为无符号字符数组
- 如何在给定文本中用字符数组替换符号
- 为什么不建议使用宏符号常量定义一个固定长度的数组呢
- 为什么C++数组索引值是有符号的,而不是围绕size_t类型构建的(或者我错了)
- C++ - 将任何文件的字节读取到无符号字符数组中