当前位置:网站首页>[C Language Brush Questions] Three Questions for Getting Started with Pointers | String Length, String Copy, Two Number Swap
[C Language Brush Questions] Three Questions for Getting Started with Pointers | String Length, String Copy, Two Number Swap
2022-08-02 19:06:00 【No. 7 Andy】
作者:柒号华仔
个人主页:欢迎访问我的主页
个人信条:星光不问赶路人,岁月不负有心人.
个人方向:主要方向为5G,同时兼顾其他网络协议,编解码协议,C/C++,linux,云原生等,感兴趣的小伙伴可以关注我,一起交流.
推荐一款模拟面试、刷题神器:*登录免费刷题
目录
前言
Brought it to my friends todayC语言刷题,一起刷题,Let's go through customs and interview together to enter the big factory,At the same time, brushing the questions is also reinforcement learning,The only way to consolidate knowledge.
The title comes from Niuke Tiba of Niuke.com,链接为:Click to jump to brush the artifact.经典高频面试题,应有尽有,各种编程语言,一网打尽.努力吧,我们都是赶路人!

)
CC1 获取字符串长度
1.1 题目描述
描述
键盘输入一个字符串,编写代码获取字符串的长度并输出,要求使用字符指针实现.
输入描述:
键盘输入一个字符串
输出描述:
输出字符串的长度
示例
输入: helloworld
输出: 10
1.2 题目解析
After the program reads the keyboard input string,字符串以’\0’作为结束符号,Use a pointer to point to this array of strings,Accumulate the length of the string by shifting the pointer,直到碰见’\0’结束.
1.3 代码实现
#include<stdio.h>
#include<string.h>
int main(void)
{
char a[64];
gets(a);
char *start=a;
char *end=a;
while(*end!='\0'){
end++;
}
printf("%d",end-start);
return 0;
}
CC2 复制部分字符串
2.1 题目描述
描述
键盘输入一个长度为len(1 <= len < 30)的字符串,再输入一个正整数 m(1 <= m <= len),将此字符串中从第 m 个字符开始的剩余全部字符复制成为另一个字符串,并将这个新字符串输出.要求用指针处理字符串.
输入描述:
键盘输入一个长度为len(1 <= len < 30)的字符串,再输入一个正整数 m(1 <= m <= len)
输出描述:
输出复制的新字符串
示例
输入: helloworld 6
输出: world
2.2 题目解析
When solving the problem, pay attention to entering the string first,Then enter the first few characters to start copying.数组是从0开始,因此mIt needs to be subtracted by one to start the calculation.The title requires processing with pointers,Arrays are not allowed.
2.3 代码实现
#include <stdio.h>
#include <string.h>
int main() {
char s[30] = {
0 };
gets(s);
int m = 0;
scanf("%d", &m);
char *p = &s[m - 1];
int n = strlen(s);
for (int i = 1; i < n - m + 1; i++) {
printf("%c", *(p + i));
}
return 0;
}
CC3 编写函数实现两数交换(指针方式)
3.1 题目描述
描述
编写一个函数,实现两个整数的交换,要求采用指针的方式实现.
输入描述:
键盘输入2个整数 m 和 n
输出描述:
输出交换后m 和 n 的值,中间使用空格隔开
示例
输入: 2 3
输出: 3 2
3.2 题目解析
The first thing to note is the use of pointers,为了实现交换,We need to define an intermediate volume for transition transformations.
3.3 代码实现
#include <stdio.h>
int main()
{
int m=0,n=0,temp=0;
int* pm=&m;
int* pn=&n;
int* pt=&temp;
scanf("%d\n%d",pm,pn);
*pt=*pm;
*pm=*pn;
*pn=*pt;
printf("%d %d\n",m,n);
return 0;
}
结语
纸上得来终觉浅,绝知此事要躬行,C语言的学习还是得基础知识+Do-it-yourself synchronization,Find a website where you can practice online,比如牛客网,多多练习,假以时日,Believe that the gains are huge,进步神速!
边栏推荐
- 持续集成(四)Jenkins配置报警机制
- sql2008 database suspicious solution _sqlserver2008 database suspicious
- 链表的归并排序[自顶向下分治 || 自低向上合并]
- MySQL常见面试题汇总(建议收藏!!!)
- 融云「 IM 进阶实战高手课」系列直播上线
- Default username and password (SQL)
- 研发了 5 年的时序数据库,到底要解决什么问题?
- PostGresql listen与notify命令
- 排查生产环境:MySQLTransactionRollbackException数据库死锁
- 在idea中创建web项目_idea部署web项目
猜你喜欢
随机推荐
Mysql开启binlog
Summary of CNN classic models [easy to understand]
numpy的学习笔记
MySQL常见函数
蔚来杯2022牛客暑期多校训练营5 ABCDFGHK
Oracle 11g rac打完补丁,dbca新建数据库还需要执行应用补丁的sql吗?
持续集成(四)Jenkins配置报警机制
【genius_platform软件平台开发】第七十五讲:YUY2转RGB24实现源码
CNN经典模型汇总[通俗易懂]
Gartner released, annual Challenger!
持续集成(三)Jenkins新增节点
MYSQL一站式学习,看完即学完
红蓝对抗经验分享:CS免杀姿势
Redis进阶之路:深度解析Redis单线程架构,图文并茂不能再清晰了
julia系列5:文本、图像、其他语言函数互动
julia系列6:并行计算
安装TimeGen波形绘图软件
【无标题】
Default username and password (SQL)
[LeetCode]剑指 Offer 32 - II. 从上到下打印二叉树 II








