由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - A question about c++ pointer
相关主题
what does this mean?static initialization dependency c++
a simple C++ questionArray in C
c++ 弱问题:static const char* const 这两个const 分别是什么意思?c++ 不自动initialize变量么?
in-class static member questionreverse words, not the Microsoft one!!!
difference between: char** p and char*p[] ??请教如何使用qsort() to sort string.
谁给解释一下这个c question这个程序怎么解决
问一个 char * 和 char [] 的问题 error LNK2001:的错误如何改正?
一个简单的小问题C++ Q05: pointer to constant variable
相关话题的讨论汇总
话题: str话题: char话题: fixed话题: static话题: 12345
进入Programming版参与讨论
1 (共1页)
d*******n
发帖数: 1339
1
see this
void foo()
{
char *str="whatever";
/*
define function here
*/
return;
}
After foo() returns, will memeory used to store *str be free? (provied that
no delete[] str is used)
s****u
发帖数: 118
2
static的

that

【在 d*******n 的大作中提到】
: see this
: void foo()
: {
: char *str="whatever";
: /*
: define function here
: */
: return;
: }
: After foo() returns, will memeory used to store *str be free? (provied that

a****l
发帖数: 8211
3
actually you can not use "delete[] str".....

that

【在 d*******n 的大作中提到】
: see this
: void foo()
: {
: char *str="whatever";
: /*
: define function here
: */
: return;
: }
: After foo() returns, will memeory used to store *str be free? (provied that

e***n
发帖数: 286
4
as long as you didn't use "new" to dynamically allocate memory, you will be
fine.
by defauly, the memory is locally allocated in the stack, not in the heap
{
char *str = "12345";
} // you will be fine, no memory leak
and
{
char *str1 = new char[6];
....
delete [] str1; // must
} // you will be fine only if you have the delete [] statement
is different.
k****f
发帖数: 3794
5
char*str="12345"; "12345"字符串不是在stack里面的,不能修改的。
char str[]="12345";这个才是在stack里面的。可以随便修改的。比如str[0]='6';

be

【在 e***n 的大作中提到】
: as long as you didn't use "new" to dynamically allocate memory, you will be
: fine.
: by defauly, the memory is locally allocated in the stack, not in the heap
: {
: char *str = "12345";
: } // you will be fine, no memory leak
: and
: {
: char *str1 = new char[6];
: ....

j******y
发帖数: 128
6
真及时,本来我也有这个疑问的。
char* str="12345"; "12345"字符串不是在stack里面的,不能修改的。
那"12345"是存在哪里的?我觉得是静态内存里,不知道对不对。
如果函数foo的返回类型是char*, 那函数结尾return str;应该可以合法返回"12345"
罗?
D*********s
发帖数: 555
7
usually it's in code space.

【在 j******y 的大作中提到】
: 真及时,本来我也有这个疑问的。
: char* str="12345"; "12345"字符串不是在stack里面的,不能修改的。
: 那"12345"是存在哪里的?我觉得是静态内存里,不知道对不对。
: 如果函数foo的返回类型是char*, 那函数结尾return str;应该可以合法返回"12345"
: 罗?

c***h
发帖数: 80
8
程序本身的数据段里 (程序有代码段、数据段、堆栈段等segment,可以去查阅汇编语
言的书籍)

【在 j******y 的大作中提到】
: 真及时,本来我也有这个疑问的。
: char* str="12345"; "12345"字符串不是在stack里面的,不能修改的。
: 那"12345"是存在哪里的?我觉得是静态内存里,不知道对不对。
: 如果函数foo的返回类型是char*, 那函数结尾return str;应该可以合法返回"12345"
: 罗?

j********e
发帖数: 7
9
When a program is loaded into memory at run time, it normally consists of
six sections:
Description | Minimum Required Access | Non-Volatile? | Run Time
Behavior
____________________________________________________________________________
__
Code |Execute-Only |Yes |Fixed/Static
Constants |Read-Only |Yes |Fixed/Static
Initialized Data |Read/Write |Yes |Fixed/Static
Uninitialized Data |Read/Write |No |Fixed/S
t****t
发帖数: 6806
10
你左右不分的?
/和\好象差别挺大的……

__

【在 j********e 的大作中提到】
: When a program is loaded into memory at run time, it normally consists of
: six sections:
: Description | Minimum Required Access | Non-Volatile? | Run Time
: Behavior
: ____________________________________________________________________________
: __
: Code |Execute-Only |Yes |Fixed/Static
: Constants |Read-Only |Yes |Fixed/Static
: Initialized Data |Read/Write |Yes |Fixed/Static
: Uninitialized Data |Read/Write |No |Fixed/S

G*O
发帖数: 706
11
应该学学编译原理之类的课程。

【在 j******y 的大作中提到】
: 真及时,本来我也有这个疑问的。
: char* str="12345"; "12345"字符串不是在stack里面的,不能修改的。
: 那"12345"是存在哪里的?我觉得是静态内存里,不知道对不对。
: 如果函数foo的返回类型是char*, 那函数结尾return str;应该可以合法返回"12345"
: 罗?

1 (共1页)
进入Programming版参与讨论
相关主题
C++ Q05: pointer to constant variabledifference between: char** p and char*p[] ??
static vector 怎么 initialize ?谁给解释一下这个c question
关于C/C++里的Static variable的memory allocation/initializa问一个 char * 和 char [] 的问题
C++: Static initialization dependency一个简单的小问题
what does this mean?static initialization dependency c++
a simple C++ questionArray in C
c++ 弱问题:static const char* const 这两个const 分别是什么意思?c++ 不自动initialize变量么?
in-class static member questionreverse words, not the Microsoft one!!!
相关话题的讨论汇总
话题: str话题: char话题: fixed话题: static话题: 12345