Mình có mấy đoạn code sau:
void trongHam(char* p1) { // trong ham thi bien p1 kieu char* se duoc luu tren Stack hay vung nho khac?(data segments ,..)
}// va minh thu thi khong the dung delete cho p1 --> co le khong luu tren heap segments.
void trongHam(char p1[50]) {
}// minh lam them cai nay va thu chay thi ham nay voi ham tren la mot --> luu tru doi so p1 la nhu nhau.
char p2[50]; // co phai p2 luu tru tren data segments va duoc khoi tao mac dinh la "" (kieu BSS)?;
char p3[50] = (char*)"Hanh phuc cua tri thuc.";//co phai p3 duoc luu tru tren data segments va da duoc khoi tao.
int main() {
char p4[50]; // co phai p4 la luu tru tren stack khong?
char* p5 = new char();// chac p5 la luu tru tren heap segments? va phai tu quan ly vung nho (phai delete(p4) khi ket thuc).
// p5 = new char();
delete(p5);
//Dieu cuoi cung la viec tro toi vung nho cua no se kiem soat nhu the nao. Cu the la su khac nhau giua
//viec dung *p5 va p5 (chang han) se tro toi vung nho kieu gi?
//Viec viet cout << &p5; la lay dia chi vung nho heap ma p5 tro toi hay vung nho tren Stack cua bien p5?
// co cach nao de lay ca vung nho cua bien p5 tren Stack va ca tren heap ma no tro toi.
}
Thanks.