3C科技 娛樂遊戲 美食旅遊 時尚美妝 親子育兒 生活休閒 金融理財 健康運動 寰宇綜合

Zi 字媒體

2017-07-25T20:27:27+00:00
加入好友
C/C++動態配置記憶體_記憶體洩漏介紹 資料來源: https://mp.weixin.qq.com/s/WvAsjLhgGlRJsxFPLAI3lw C code /* https://mp.weixin.qq.com/s/WvAsjLhgGlRJsxFPLAI3lw https://www.tutorialspoint.com/compile_c_online.php */ #include int main() { char arr_char[1024*1000000]; arr_char[0] = '0'; } /* $gcc -o main *.c $main /usr/bin/timeout: the monitored command dumped core sh: line 1: 182320 Segmentation fault /usr/bin/timeout 10s main */ /* https://mp.weixin.qq.com/s/WvAsjLhgGlRJsxFPLAI3lw https://www.tutorialspoint.com/compile_c_online.php */ #include #include #include int main() { char *p1 = (char *)malloc(1024*1000000); strcpy(p1, "这里是堆区"); printf("%s\n", p1); free(p1); } /* $gcc -o main *.c $main 这里是堆区 */ © 2021 GitHub, Inc. C++ code //https://mp.weixin.qq.com/s/WvAsjLhgGlRJsxFPLAI3lw //https://www.tutorialspoint.com/compile_cpp_online.php #include using namespace std; class Babe { public: Babe() { cout << "Create a Babe to talk with me" << endl; } ~Babe() { cout << "Babe don\'t Go away,listen to me" << endl; } }; int main() { int *a = new int[10]; for(int i=0;i<10;i++) { a[i]=i; cout<< a[i]< delete pbabe; pbabe = new Babe[3]; delete[] pbabe; return 0; } /* $g++ -o main *.cpp $main 0 1 2 3 4 5 6 7 8 9 Create a Babe to talk with me Create a Babe to talk with me Create a Babe to talk with me Babe don't Go away,listen to me Babe don't Go away,listen to me Babe don't Go away,listen to me Create a Babe to talk with me Create a Babe to talk with me Create a Babe to talk with me Babe don't Go away,listen to me Babe don't Go away,listen to me Babe don't Go away,listen to me */ © 2021 GitHub, Inc. 圖文版完整內容:

本文由jashliaoeuwordpress提供 原文連結

寫了 5860316篇文章,獲得 23313次喜歡
精彩推薦