当前位置:网站首页>字符指针赋值[通俗易懂]
字符指针赋值[通俗易懂]
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
边栏推荐
- How does automated testing create business value?
- Ubantu专题4:xshell、xftp连接接虚拟机以及设置xshell复制粘贴快捷键
- ansible study notes 02
- The normal form of the database (first normal form, second normal form, third normal form, BCNF normal form) "recommended collection"
- AVH Deployment Practice (1) | Deploying the Flying Paddle Model on Arm Virtual Hardware
- RecyclerView高效使用第二节
- Why is the field of hacking almost filled with boys?
- ML.NET related resources
- 浏览器自带的拾色器
- ASP.NET Core generates continuous Guid
猜你喜欢
Kubernetes常用命令
BGP综合实验(建立对等体、路由反射器、联邦、路由宣告及聚合)
Why is the field of hacking almost filled with boys?
mysql black window ~ build database and build table
Getting Started with TextBlock Control Basic Tools Usage, Get Started
[MySQL] Mysql paradigm and the role of foreign keys
工程流体力学复习
Kubernetes原理剖析与实战应用手册,太全了
button控件的使用
mongo enters error
随机推荐
vb中如何连接mysql_vb怎么连接数据库「建议收藏」
Kubernetes common commands
Grafana安装后web打开报错
TRACE32 - Common Operations
Delete table data or clear table
第二届中国PWA开发者日
Emmet 语法
01 Encounter typescript, build environment
工程水文学名词解释总结
国内市场上的BI软件,到底有啥区别
TRACE32 - SNOOPer-based variable logging
After Grafana is installed, the web opens and reports an error
Snake Project (Simple)
Ubantu专题4:xshell、xftp连接接虚拟机以及设置xshell复制粘贴快捷键
数据表插入数据insert into
hough变换检测直线原理(opencv霍夫直线检测)
做事软件开发-法的重要性所在以及合理结论的认识
Public Key Retrieval is not allowed error solution when DBeaver connects to MySQL 8.x
C语言”三子棋“升级版(模式选择+AI下棋)
Replication Latency Case (3) - Monotonic Read