in place new

joel-q發表於2024-08-08

// https://www.online-cpp.com/
#include<iostream>
using namespace std;
int main() {
    char c1 = '1';
    cout << c1 << endl;
    char *pc2 = new (&c1) char;
    cout << c1 << endl;
    c1 = '2';
    cout << *pc2 << endl;
    return 0;
}
// 1
// 1
// 2

相關文章