调用函数后,程序不会运行到最后
Program wont run to the end after function is called
我编写了一个程序来接受数组中的 15 个整数值,然后将这个数组传递给一个函数,该函数将每个偶数索引值乘以 4。
目前程序显示初始数组,但似乎在显示修改后的数组之前它被挂起了。
请帮助我理解为什么该程序卡在这里!
int main(){
const int SIZE = 15;
int quad[SIZE] = {};
void quadruple(int[], const int);
cout << "Enter 15 integer values into an array." << endl;
for (int i = 0; i < SIZE; i++) // Accept 15 int values
{
cout << i << ": ";
cin >> quad[i];
}
cout << "Before quadruple function is called: " << endl;
for (int i = 0; i < SIZE; i++)
{
cout << quad[i] << " ";
}
cout << endl;
quadruple(quad, SIZE);
cout << "After even index value multiplication: " << endl;
for (int i = 0; i < SIZE; i++)
{
cout << quad[i] << " ";
}
cout << endl;
return 0;
}
void quadruple(int values[], const int SZ){
for (int i = 0; i < SZ; i + 2) // Multiply even values by 4
{
if ((i % 2) == 0)
{
values[i] = values[i] * 4;
}
else // Keep odd values the same
{
values[i] = values[i] * 1;
}
}
}
for (int i = 0; i < SZ; i + 2)
"I + 2"不执行任何操作。
你可能的意思是"i += 2;"。
您的家庭作业是查找有关系统调试器的一些文档。并找到你的橡皮鸭在哪里,正如评论中建议的那样。
相关文章:
- 运行同一解决方案的另一个项目的项目
- CMake-按正确顺序将项目与C运行时对象文件链接
- 如何运行位于boost/libs/python/example/tutorial目录中的hello.cpp和Jamfil
- 代码在main()中运行,但在函数中出现错误
- 我在c++代码中生成了一个运行时#3异常
- 如何在linux终端中同时编译和运行c++代码
- 读取文件的最后一行并输入到链接列表时出错
- 为什么在运行时没有向我们提供有关分段错误的更多信息?
- 如何在运行中期切换GTK CSS style_context
- 为什么输入文件的最后一行运行两次?
- 为什么当我在Visual c ++ studio 2010中运行应用程序时光标会转到最后一个文本框
- 调用函数后,程序不会运行到最后
- 我的线程工作不好,它给出了所有结果,最后没有一个接一个,GUI 在线程运行期间挂起?
- C++ 开关结构(运行最后一种情况两次)
- 如何在最后一个窗口关闭时保持应用程序运行
- 程序在VS2008中运行良好,在程序的最后在VS2010中抛出异常
- 为什么最后一行的运行结果是"Segmentation fault (core dumped)"
- mfccfiledialog在用户最后运行时选择的位置打开
- 非常奇怪的行为:我的c++程序突然退出,但它在Eclipse CDT的调试模式下完美地运行到了最后
- 如何在运行时错误发生之前检查.cpp文件的最后一行