当前位置:网站首页>字符指针赋值[通俗易懂]
字符指针赋值[通俗易懂]
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
边栏推荐
- The principle of hough transform detection of straight lines (opencv hough straight line detection)
- leetcode303场周赛复盘
- 苹果官网样式调整 结账时产品图片“巨大化”
- MySQL数据库操作
- Public Key Retrieval is not allowed error solution when DBeaver connects to MySQL 8.x
- Why is the field of hacking almost filled with boys?
- R language ggplot2 visualization: use the ggmapplot function of the ggpubr package to visualize the MA plot (MA-plot), the font.legend parameter and the font.main parameter to set the title and legend
- 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
- mysql黑窗口~建库建表
- Unity 之 图集属性详解和代码示例 -- 拓展一键自动打包图集工具
猜你喜欢
The new BMW 3 Series is on the market, with safety and comfort
WPF项目--控件入门基础用法,必知必会XAML
AVH Deployment Practice (1) | Deploying the Flying Paddle Model on Arm Virtual Hardware
6-22漏洞利用-postgresql数据库密码破解
工程流体力学复习
01 邂逅typescript,环境搭建
mongo进入报错
苹果官网样式调整 结账时产品图片“巨大化”
Kubernetes原理剖析与实战应用手册,太全了
Browser's built-in color picker
随机推荐
JVM parameter analysis Xmx, Xms, Xmn, NewRatio, SurvivorRatio, PermSize, PrintGC "recommended collection"
ansible study notes 02
Matlab matrix basic operations (definition, operation)
[MySQL] Mysql paradigm and the role of foreign keys
浏览器自带的拾色器
【MySQL】Mysql范式及外键作用
Codeforces Round #796 (Div. 2)(A-D)
TRACE32——C源码关联
Handling write conflicts under multi-master replication (4) - multi-master replication topology
Destruction order of thread_local variables
Matlab矩阵基本操作(定义,运算)
WPF project - basic usage of controls entry, you must know XAML
Bilateral filtering acceleration "recommended collection"
国内市场上的BI软件,到底有啥区别
ML.NET相关资源整理
RecyclerView的高效使用第一节
Efficient use of RecyclerView Section 2
BGP综合实验(建立对等体、路由反射器、联邦、路由宣告及聚合)
The R language ggstatsplot package ggbarstats function visualizes bar charts, and adds hypothesis test results (including sample number, statistics, effect size and its confidence interval, significan
对话庄表伟:开源第一课