当前位置:网站首页>字符指针赋值[通俗易懂]
字符指针赋值[通俗易懂]
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
边栏推荐
猜你喜欢

6-22 Vulnerability exploit - postgresql database password cracking

WPF project - basic usage of controls entry, you must know XAML

01 Encounter typescript, build environment

苹果官网样式调整 结账时产品图片“巨大化”

What is the difference between BI software in the domestic market?

微信聊天记录中搜索红包

Kubernetes principle analysis and practical application manual, too complete

国内市场上的BI软件,到底有啥区别

AVH部署实践 (一) | 在Arm虚拟硬件上部署飞桨模型

WPF项目--控件入门基础用法,必知必会XAML
随机推荐
01 Encounter typescript, build environment
Emmet 语法
JVM parameter analysis Xmx, Xms, Xmn, NewRatio, SurvivorRatio, PermSize, PrintGC "recommended collection"
工程流体力学复习
更新数据表update
国内市场上的BI软件,到底有啥区别
Qt practical cases (54) - using transparency QPixmap design pictures
RecyclerView的高效使用第一节
Grafana安装后web打开报错
Replication Latency Case (3) - Monotonic Read
数据表插入数据insert into
button控件的使用
修改SQL语言实现Mysql 多表关联查询优化
TRACE32 - Common Operations
【CUDA学习笔记】初识CUDA
数据库的范式(第一范式,第二范式,第三范式,BCNF范式)「建议收藏」
Delete table data or clear table
基于ABP实现DDD
R language ggplot2 visualization: use the ggboxplot function of the ggpubr package to visualize the grouped box plot, use the ggpar function to change the graphical parameters (caption, add, modify th
Word table to Excel