VS Debug和Release的介绍

    科技2022-08-29  106

    Debug版本下:

    #include<stdio.h> #include<stdlib.h> int main() { int i = 0; int arr[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; printf("&i=%p\n", &i); for (i = 0; i <= 12; i++) { arr[i] = 0; printf("hehe\n"); } //让代码走到这里暂停 system("pause"); return 0; }

    输出结果:

    是什么导致了这样的问题?

    Release版本下

    #include<stdio.h> #include<stdlib.h> int main() { int i = 0; int arr[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; printf("&i=%p\n", &i); for (i = 0; i <= 12; i++) { arr[i] = 0; printf("hehe\n"); } //让代码走到这里暂停 system("pause"); return 0; }

    输出结果:

    我们发现没有死循环打印hehe,而是正好打印了13个hehe。接下来我们用一段代码检测一下做了什么改变:

    #include<stdio.h> #include<stdlib.h> int main() { int i = 0; int arr[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; printf("&i=%p\n", &i); for (i = 0; i <= 12; i++) { arr[i] = 0; //printf("hehe\n"); printf("&arr[%d]=%p\n", i, &arr[i]); } //让代码走到这里暂停 system("pause"); return 0; }

    输出结果:

    由此我们可以发现在Release版本下做了优化,具体如下:

    Processed: 0.008, SQL: 9