什么是char *? [英] What is a char*?

查看:135
本文介绍了什么是char *?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我一直在看一个大学关于C ++的讲座,我在学习很多,但有一件事我还是不能理解的:

So I've been watching lectures from a University about C++, and I'm learning a lot, but one thing I still cannot understand is this:

为什么你有时必须这样做吗?

Why do you have to do this sometimes?

char* test = "testing";

根据我已经阅读/看过的内容,我不明白为什么你必须把 * 。从我以为我明白,你只使用 * 如果你有一个地址,但也许我只是死了错。

From what I've read/watched, I just don't understand why you have to put the *. From what I thought I understood, you only use * if you have an address, but maybe I'm just dead wrong.

推荐答案

这是一个 char

char c = 't';

它只能保留一个 char acter ! :)

It can only hold one character at a time! :)

这是一个C字符串:

char sz[] = "test";

它可以持有多于一个 char actor。

It can "hold" more than just one character.

A char * 指向多个 char 的序列的内存位置。

A char* points to the memory location of a sequence of multiple chars.

char sz[] = {'t', 'e', 's', 't', 0};

const char *psz = "test";

注意:

*psz == 't';
*(psz + 1) == 'e';
*(psz + 2) == 's';
*(psz + 3) == 't';
*(psz + 4) == 0; // NUL

和:

sz[0] == 't';
sz[1] == 'e';
sz[2] == 's';
sz[3] == 't';
sz[4] == 0; // NUL

这篇关于什么是char *?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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