我必须free()const char *吗? [英] do I have to free() a const char * ?

查看:888
本文介绍了我必须free()const char *吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想知道我是否必须对const char *指针或字符串(idk是哪个)调用free().我之所以奇怪,是因为*,这似乎意味着它是一个指针.这是我的方法:

Hi, I''m just wondering if I have to call free() on a const char * pointer or string (idk which one it is). The reason why I''m wondering this is because of the *, which would seem to imply that it''s a pointer. This is how I do it:

const char * filenames[2] = {"file1.png", "file2.png"};



预先感谢您的所有答复! -B



Thanks in advance for any and all replies! -B

推荐答案

不,在这种情况下不可以,因为没有使用malloc和friends动态分配内存:)

释放它将是一个错误...

问候
Espen Harlinn
No, not in this case as the memory was not dynamically allocated using malloc and friends :)

Freeing it would be an error ...

Regards
Espen Harlinn


new —否delete.以同样的方式,没有malloc(或callocrealloc)—没有free.这样简单吗?

—SA
PS :再次感谢CPallini
No new — no delete. In the same way, no malloc (or calloc or realloc) — no free. Isn''t that simple?

—SA
P.S.: Thanks again, CPallini


释放文件名[2]!

请随时忽略此帖子. :-O
Free the filenames[2]!

Please feel free to to ignore this posting. :-O


这篇关于我必须free()const char *吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆