C中的字符指针 [英] Char pointers in C

查看:57
本文介绍了C中的字符指针的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨。


我正在试图弄清楚C中的指针和内存分配。我在互联网上阅读了不少解释并阅读了一些内容我有的书,但我不是那么聪明......


我想做的是创建一个包含五个字符指针的数组。我希望能够通过setParams函数为params数组指定一个指针。我不明白我没有得到什么,但肯定有一些东西。看起来这样可行:

Hi.

I''m trying to figure out pointers and memory allocation in C. I''ve read quite a few explanations on the internet and have read in a few books that I''ve got, but I''m not so much smarter yet...

What I want do do is to create an array of five pointers to characters... I want to make it possible to assign a pointer to the params array tohrough the setParams function. I don''t understand what I have not gotten, but there is certainly something. It seems like this works:

展开 | 选择 | Wrap | 行号

推荐答案

展开 < span class =codeDivider> | 选择 | Wrap | 行号


展开 | 选择 | Wrap | 行号



我不喜欢malloc,但似乎你必须将它转换为你想要的数据类型
I''m not that familliar with malloc, but it seems you have to cast it to the data type you want



否你不必投下malloc,你可能不想,因为它没有帮助,但可以伤害。除非你想在C ++下编译,否则C会隐式执行转换。


krreks,你不会写val1 ++。您可以对其进行索引,例如val1 [2]。你基本上有一个数组(动态分配),你可以索引该数组,对吗?想想阵列。


另请阅读 http:// c -faq.com/ 相关章节。指针与数组部分特别有用。

No. You don''t have to cast malloc, and you probably don''t want to, as it doesn''t help but can hurt. Unless you want to compile under C++, C will implicitly do the cast.

krreks, you wouldn''t write val1++. You can index it, such as val1[2]. You essentially have an array (dynamically allocated), and you can index that array, right? Think about arrays.

Also read http://c-faq.com/ on the relevant sections. The pointers vs. arrays section is particularly helpful.


这篇关于C中的字符指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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