当前位置:网站首页>字符指针赋值[通俗易懂]
字符指针赋值[通俗易懂]
2022-07-31 15:38:00 【全栈程序员站长】
大家好,又见面了,我是你们的朋友全栈君。
程序1:把两个相同的字符串赋值给两个不同的指针。比较两个指针
#include<stdio.h> int main(void) { char *a;
printf(“%p/n”,a); printf(“%d/n”,sizeof(a)); //定义一个指针(一个字节),指针变量里面的值是随机的,所以这个指针也叫悬空指针。 a = “hello”; printf(“%p/n”,a); printf(“%d/n”,sizeof(a)); char *b=”hello”; printf(“%p/n”,b); printf(“%d/n”,sizeof(b));
if(a==b) printf(“YES”); else printf(“NO”); getchar();
}
程序2:把两个相同的字符赋值给两个不同的指针。比较两个指针
#include<stdio.h> int main(void) { char *a; printf(“%p/n”,a); printf(“%d/n”,sizeof(a)); //定义一个指针(一个字节),指针变量里面的值是随机的,所以这个指针也叫悬空指针。 a = ‘A’; printf(“%p/n”,a); printf(“%d/n”,sizeof(a)); char *b=’A’; printf(“%p/n”,b); printf(“%d/n”,sizeof(b));
if(a==b) printf(“YES”); else printf(“NO”); getchar();
}
程序3:把字符串“A”赋值给字符指针;
#include<stdio.h> int main(void) { char *a; printf(“%p/n”,a); printf(“%d/n”,sizeof(a)); a = “A”; printf(“%p/n”,a); printf(“%d/n”,sizeof(a)); char *b=”A”; printf(“%p/n”,b); printf(“%d/n”,sizeof(b));
if(a==b) printf(“YES”); else printf(“NO”); getchar();
}
结果是
1.
2.
3.
总结:
1.把字符串赋值给指针,就是把字符串的首地址传递给指针。
2.把字符赋值给指针, 就是把字符的ACSII传递给指针。
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/127987.html原文链接:https://javaforall.cn
边栏推荐
- Gorm—Go language database framework
- mongo enters error
- 为什么毕业季不要表白?
- 工程水文学试卷
- Matlab matrix basic operations (definition, operation)
- MySQL数据库操作
- TRACE32 - C source code association
- leetcode303 Weekly Match Replay
- WPF project - basic usage of controls entry, you must know XAML
- Kubernetes principle analysis and practical application manual, too complete
猜你喜欢
随机推荐
org.apache.jasperException(could not initialize class org)
R language test whether the sample conforms to normality (test whether the sample comes from a normally distributed population): shapiro.test function tests whether the sample conforms to the normal d
[MySQL] Mysql paradigm and the role of foreign keys
update data table update
.NET 20周年专访 - 张善友:.NET 技术是如何赋能并改变世界的
ASP.NET Core generates continuous Guid
为什么黑客领域几乎一片男生?
6-22 Vulnerability exploit - postgresql database password cracking
外媒所言非虚,苹果降价或许是真的在清库存
Delete table data or clear table
工程水文学名词解释总结
radiobutton的使用
四象限时间管理有多好用?
Visualize GraphQL schemas with GraphiQL
Dialogue with Zhuang Biaowei: The first lesson of open source
Implementing click on the 3D model in RenderTexture in Unity
TextBlock控件入门基础工具使用用法,取上法入门
全新宝马3系上市,安全、舒适一个不落
双边滤波加速「建议收藏」
leetcode303 Weekly Match Replay









