c语言练习题40:深入理解字符串常量

深入理解字符串常量

cpp 复制代码
#include<stdio.h>
int main() {
	char str1[] = "abcd";
	char* str2 = "abcd";
	printf("%s\n", str1);
	printf("%s\n", str2);
	return 0;
}

char str1[] = "abcd";是用字符串初始化数组。

char* str2 = "abcd"; "abcd"为字符串常量

字符串常量不能被修改

例如1:

cpp 复制代码
#include<stdio.h>
int main(int argc,const char*argv[]) {
	char* a[] = { "Work","at","huawei" };
	char** p = a;
	*(*(p + 2) + 1) = 'H';
	printf("%c %c\n", a[2][1], *(*(p + 2) + 1));
	return 0;
}

VS环境下没有输出,但linux下会报错

例如2:

相关推荐
Shanxun Liao1 小时前
Cenots 7.9 配置多台 SSH 互信登陆免密码
linux·运维·ssh
j_xxx404_1 小时前
Linux:第一个程序--进度条|区分回车与换行|行缓冲区|进度条代码两个版本|代码测试与优化
linux·运维·服务器
wadesir2 小时前
Rust中的条件变量详解(使用Condvar的wait方法实现线程同步)
开发语言·算法·rust
looking_for__2 小时前
【Linux】Ext系列文件系统
linux
yugi9878382 小时前
基于MATLAB实现协同过滤电影推荐系统
算法·matlab
TimberWill2 小时前
哈希-02-最长连续序列
算法·leetcode·排序算法
Morwit2 小时前
【力扣hot100】64. 最小路径和
c++·算法·leetcode
leoufung2 小时前
LeetCode 373. Find K Pairs with Smallest Sums:从暴力到堆优化的完整思路与踩坑
java·算法·leetcode
OliverH-yishuihan3 小时前
开发linux项目-在 Windows 上 基于“适用于 Linux 的 Windows 子系统(WSL)”
linux·c++·windows
wifi chicken3 小时前
数组遍历求值,行遍历和列遍历谁更快
c语言·数据结构·算法