美文网首页
2019-06-23 基础知识

2019-06-23 基础知识

作者: hangzhou吴彦祖 | 来源:发表于2022-04-17 20:19 被阅读0次

    1:C++的程序在编译时候内存可以分为五大存储区:堆区、栈区、全局区、文字常量区、程序代码区。

    2:int* ptr=NULL; ptr=(int*)malloc(1000*sizeof(int));  if(NULL == ptr) exit; free ptr; ptr=null;

    3:new 调用operator new函数,调用对应的构造函数,传入初值,对象构造完成后,返回一个指向该对象的指针

    new delete 和malloc和free的区别:

    new delete是操作符 可以重载,malloc和free是函数  new delete会调用构造与析构,而malloc和free仅仅分配内存

    malloc分配内存大小需要指定,new的编译器会自己计算。new比malloc更安全。

    Windows内存管理的方法:

    include "stdafx.h"

    #include<iostream>

    #include<string>

    using namespace std;

    int _tmain(int argc, _TCHAR* argv[])

    {

    string a;

    std::cin >> a;

    //a = cin.get();

    int i = 0, j;

    char t;

    for (i = 0, j = a.length()-1; i < a.length() / 2; i++, j--)

    {

    t = a.at(i);

    a.at(i)=a.at(j);

    a.at(j) = t;

    }

    cout << a;

    return 0;

    }

    相关文章

      网友评论

          本文标题:2019-06-23 基础知识

          本文链接:https://www.haomeiwen.com/subject/kkcwqctx.html