C/C ++ For loop statement efficiency test optimization and runtime error: Stack Overflow solution in multiple loops, if possible, should put the longest loop in the innermost layer, the shortest cycle is placed on the outermost layer to reduce the number of times the CPU switches across the cycle layer. Use the following code to test the efficiency of nested For loops: [cpp] // For nested performance. cpp: Defines the entry point for the console application. // # include "stdafx. h "# include <iostream> # include <time. h> using namespace std; int main (void) {clock_t cstart, cends; cstart = clock (); long sum1 = 0; long a1 [5] [1, 10000000]; for (long I = 0; I <5; I ++) {for (long j = 0; j <10000000; j ++) {sum1 + = a1 [I] [j] ;}} cout <"sum1 =:" <sum1 <endl; cends = clock (); cout <"Clock time difference:" <cends-cstart <endl; //////////////////////////////////////// /// // cstart = clock (); long sum = 0; long a [10000000] [5]; for (I = 0; I <10000000; I ++) {for (long j = 0; j <5; j ++) {sum + = a [I] [j] ;}} cout <"sum =:" <sum <endl; cends = clock (); cout <"Clock time difference:" <cends-cstart <endl; //////////////////////////////////////// /// // system ("pause "); return 0;} running result: the above Code is compiled on Windows Server 2008x64. The IDE is Microsoft Visual c ++ sp6 and can be compiled, but an error occurs during running: runtime error: Stack Overflow solution: