C语言中Pointer, Array,String and Structures的区别

本文详细介绍了C语言中的指针、字符串、字符串数组的概念和操作。指针用于动态内存分配等任务,字符串以''结尾,C语言中用字符数组表示。字符串数组可以作为二维数组或一维数组处理。文章还涵盖了字符串的初始化、赋值、输出、输入以及库函数如strlen、strcat和strcmp的使用。
摘要由CSDN通过智能技术生成



指针(pointer )

Tasks, such as dynamic memory allocation, cannot be performed without using pointers. 

Every variable is a memory location and every memory location has its address defined which can be accessed using ampersand (&) operator, which denotes an address in memory. 

pointer is a variable whose value is the address of another variable, i.e., direct address of the memory location. Like any variable or constant, you must declare a pointer before using it to store any variable address.

Access the value at the address available in the pointer variable. using unary operator * 


字符串(string)

用双引号引起来的就是字符串

"a string"

// C语言编译器会将两个并列的字符串自动拼接成一个字符串

"a string""another a string"

// 折行符'\'是代码换行连接的标记(一行不够写)

"a looooooooooong \

 string

常见ASCII编码:

  'A' == 65    'a' == 97    '0' == 48    '\0' == 0

int a[10]; //表示在栈中分配了40Bytes的内存空间,空间的首地址是a

char a[10]; //表示在栈中分配了10Bytes的内存空间,空间的首地址是a


如何表示和保存字符串:

    C语言中没有字符串类型

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值