为const char指针赋值 [英] const char pointer assignments
本文介绍了为const char指针赋值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是以下分配有效吗?或将任何这些产生问题。请建议。
为const char * C1;
为const char * C2;
为const char * C3;
字符* C4;C2 = C1;
C2 = C3;
C2 = C4;
如果我这样做,是正常事是什么?
为const char * C5 =XYZ;
char *之C6 =ABC;C2 = C5;
C2 = C6;
解决方案
在你的心中画通过asterik一条线。左边是被指向和向右什么类型的指针
什么例如
-
为const char * const的P
- 指针P
是恒定的,因此是<$ C $字符C> p 点 - 即不能改变指针和内容都什么p
点 -
为const char * P
-P
指向常量字符。您可以更改P
的价值,让它指向不同的常量字符。但无论P
点,你不能改变的内容。 -
char * const的P
- 你是无法改变的指针,但可以改变的内容
最后
-
的char * P
- 一切都待价而沽
希望有所帮助。
Are the following assignments valid? Or will any of these create problems. Please suggest.
const char * c1;
const char * c2;
const char * c3;
char * c4;
c2 = c1;
c2 = c3;
c2 = c4;
What if I do the following, is that ok thing to do?
const char * c5 = "xyz";
char * c6 = "abc";
c2 = c5;
c2 = c6;
解决方案
In your mind draw a line through the asterik. To the left is what is being pointed to and to the right what type of pointer
For example
const char * const p
- The pointerp
is constant and so are the characters thatp
points to - i.e. cannot change both the pointer and the contents to whatp
points toconst char * p
-p
points to constant characters. You can change the value ofp
and get it to point to different constant characters. But whateverp
points to, you cannot change the contents.char * const p
- You are unable to change the pointer but can change the contents
and finally
char * p
- Everything is up for grabs
Hope that helps.
这篇关于为const char指针赋值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文