基础例子

本文通过两个示例展示了如何使用C语言进行字符串拼接及数组元素访问。第一个示例中,利用`sprintf`函数将两个字符串I和linux拼接起来并打印;第二个示例进一步演示了数组的初始化、访问以及递增操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1 #include <stdio.h>
2 #include <stdlib.h>
3 int main()
4 {
5 char s[1024];
6 char * ss = s;
7 char * who=" I";
8 char * whom = " linux";
9 sprintf(s, "%s love %s\n", who, whom);
10 printf("--------------\n");
11 printf(ss);
12
13 }
------------------------------------------------------------------------------------
1 #include <stdio.h>
2 #include <stdlib.h>
3 int main()
4 {
5 char s[1024];
6 char * ss = s;
7 char * who="I";
8 char * whom = " linux";
9
10 int a[] = {1,2,3};
11 int *aa = a;
12 sprintf(s, "%s love %s\n", who, whom);
13 printf("--------------\n");
14 printf("%c\n",*ss);
15
16 printf("%d,\n",aa[0]);
17 aa++;
18 printf("%d\n",*aa);
19
20 }

result:
--------------
I
1,
2
------------------------------------------------------------------------------
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值