当前位置: 首页 > news >正文

如何布置网站东阳便宜营销型网站建设

如何布置网站,东阳便宜营销型网站建设,做三盛石材网站的公司,上海网站建设上海黄金坚持就是胜利 文章目录 一、实例二、如何写出好#xff08;易于调试#xff09;的代码1、优秀的代码2、示范#xff08;1#xff09;模拟 strcpy 函数方法一#xff1a;方法二#xff1a;方法三#xff1a;有弊端方法四#xff1a;对方法三进行优化assert 的使用 方法五… 坚持就是胜利 文章目录 一、实例二、如何写出好易于调试的代码1、优秀的代码2、示范1模拟 strcpy 函数方法一方法二方法三有弊端方法四对方法三进行优化assert 的使用 方法五对方法三、方法四进行优化1、解决char*问题一怎么返回 起始地址解决办法 2、解决const因为 const char* source可能出现的问题修饰指针 的作用 方法六最终的正确结果 2模拟 strlen 函数 三、编程常见的错误1、编译型错误语法错误2、链接型错误3、运行时错误 四、做一个有心人积累排错经验。 一、实例 #include stdio.hint main() {int i 0;int arr[10] { 1,2,3,4,5,6,7,8,9,10 };for (i 0; i 12; i){arr[i] 0;printf(hehe\n);}return 0; } 这段程序非常依赖当前所在的编译环境的编译环境不同出现的效果也是不同的。 类似的题目 上一篇文章介绍了在Debug版本下上述代码会死循环。 但是在Release版本下上述代码不会死循环。 原因如下 二、如何写出好易于调试的代码 1、优秀的代码 1、代码运行正常 2、BUG很少 3、效率很高 4、可读性高 5、可维护性高 6、注释清晰 7、文档齐全 常见的coding技巧 1、使用 assert 2、尽量使用 const 3、养成良好的编码风格 4、添加必要的注释 5、避免编码的陷阱 2、示范 1模拟 strcpy 函数 char * strcpy ( char * destination, const char * source ); Copies the C string pointed by source into the array pointed by destination, including the terminating null character (and stopping at that point). (第二句英文包含结束字符 ‘\0’) 将’h’,‘e’,‘l’,‘l’,‘o’,‘\0’ 传给arr2数组 方法一 #include stdio.h #include string.hint main() {char arr1[] hello; //将h,e,l,l,o,\0 传给arr2[]数组char arr2[20] { 0 }; //别忘了 结束标志 \0strcpy(arr2, arr1);printf(%s\n, arr2);return 0; }方法二 #include stdio.h #include string.hint main() {char arr1[] hello;char arr2[20] { 0 };printf(%s\n, strcpy(arr2, arr1));return 0; }方法三有弊端 #include stdio.hvoid my_strcpy(char* dest, char* src) {while (*src ! \0) //或者简洁点写成 while(*src){*dest *src;dest;src;} }int main() {char arr1[] hello;char arr2[20] { 0 };my_strcpy(arr2, arr1);printf(%s\n, arr2);return 0; }#include stdio.hvoid my_strcpy(char* dest, char* src) {while (*dest *src){dest;src;} }int main() {char arr1[] hello;char arr2[20] { 0 };char* ps NULL;my_strcpy(arr2, arr1);printf(%s\n, arr2);return 0; }#include stdio.hvoid my_strcpy(char* dest, char* src) {while (*dest *src) //先执行后置 再 解引用 *{; //空语句 //什么都不做} }int main() {char arr1[] hello;char arr2[20] { 0 };char* ps NULL;my_strcpy(arr2, arr1);printf(%s\n, arr2);return 0; }虽然可以正常输出但是遇到 空指针 NULL ,就会出错 #include stdio.hvoid my_strcpy(char* dest, char* src) {while (*src ! \0){*dest *src;dest;src;} }int main() {char arr1[] hello;char arr2[20] { 0 };char* ps NULL; //此时 ps 是 空指针空指针 是 不能直接使用的my_strcpy(ps, arr1); //这样子整个代码是什么都输出不了的空指针 是 不能直接使用的printf(%s\n, *(ps)); //什么都输出不了程序报错return 0; }方法四对方法三进行优化 assert 的使用 头文件#include assert.h assert 的作用会清晰的告诉你哪一行的代码出现了错误 #include stdio.h#include assert.h //assert 的头文件void my_strcpy(char* dest, char* src) {//断言 assertassert(dest ! NULL); //dest 不允许为 空指针assert(src ! NULL); //src 不允许为 空指针while (*src ! \0){*dest *src;dest;src;} }int main() {char arr1[] hello;char arr2[20] { 0 };char* ps NULL; my_strcpy(ps, arr1); printf(%s\n, *(ps)); return 0; }方法五对方法三、方法四进行优化 从方法一 ~ 方法四my_strcpy函数的返回值都是 void . 因为并没有 return 所以都是 void。 然而根据 strcpy函数的定义 char * strcpy ( char * destination, const char * source ); 返回值的类型应该是char * const char* source要有 const 1、解决char* 问题一怎么返回 起始地址 #include stdio.hchar* my_strcpy(char* dest, char* src) {//断言assert(dest ! NULL);assert(src ! NULL);while (*dest *src){; }return dest; //此时的 dest 已经指向了数组的最后了返回之后无法输出想要的字符串 } //我们需要的是目标函数的 起始地址int main() {char arr1[] hello;char arr2[20] { 0 };my_strcpy(arr2, arr1);printf(%s\n, arr2);return 0; }解决办法 #include stdio.h #include assert.hchar* my_strcpy(char* dest, char* src) {char* ret dest; //问题得到解决//断言assert(dest ! NULL);assert(src ! NULL);while (*dest *src){;}return ret; //就是这么简单 }int main() {char arr1[] hello;char arr2[20] { 0 };printf(%s\n, my_strcpy(arr2, arr1));return 0; } 2、解决const因为 const char* source 可能出现的问题 #include stdio.h #include assert.hchar* my_strcpy(char* dest, char* src) {char* ret dest; //问题得到解决//断言assert(dest ! NULL);assert(src ! NULL);while (*src *dest) //本来应该是while (*dest *src){ //但是写成了while (*src *dest)。;}return ret; //就是这么简单 }int main() {char arr1[] hello;char arr2[20] xxxxxxxxxxxxx;printf(%s\n, my_strcpy(arr2, arr1));return 0; }#include stdio.h #include assert.hchar* my_strcpy(char* dest,const char* src) //添加 const {char* ret dest; //问题得到解决//断言assert(dest ! NULL);assert(src ! NULL);while (*src *dest) //本来应该是while (*dest *src){ //但是写成了while (*src *dest)。;}return ret; //就是这么简单 }int main() {char arr1[] hello;char arr2[20] xxxxxxxxxxxxx;printf(%s\n, my_strcpy(arr2, arr1));return 0; } 修饰指针 的作用 结论 1、const 如果放在 * 的 左边修饰的是 指针指向的内容保证指针指向的内容不能通过指针来改变。但是指针变量本身的内容可变。 2、const 如果放在 * 的 右边修饰的是指针变量本身保证了指针变量的内容不能修改但是指针指向的内容可以通过指针改变。 #include stdio.hint main() {const int num 100; //下面的截图中忘记添加 const 了应该是 const int num 100;int a 90;const int* ps num;//*ps 200; //不能这样改变ps a;printf(%d\n, *(ps));return 0; }#include stdio.hint main() {const int num 10;//int abc 200;int* const ps num;//ps abc; //错误*(ps) 200;printf(%d\n, num);return 0; }方法六最终的正确结果 #include stdio.h#include assert.hchar* my_strcpy(char* dest, const char* src) //const 在 * 的左边 { //保证 指针指向的内容不会发生改变char* ret dest;//断言assert(dest ! NULL);assert(src ! NULL);while (*dest *src){; //空语句什么都不做}return ret; }int main() {char arr1[] hello;char arr2[20] { 0 };char* ps NULL;printf(%s\n, my_strcpy(arr2, arr1));return 0; }2模拟 strlen 函数 size_t strlen ( const char * str ); %u 或者 %zd 来打印 无符号整型unsigned int。 The length of a C string is determined by the terminating null-character: A C string is as long as the number of characters between the beginning of the string and the terminating null character (without including the terminating null character itself). 最后一句话字符串的长度 不包含 结束字符 ‘\0’。 #include stdio.h #include assert.hsize_t my_strlen(const char* src) {int count 0;//断言assert(src ! NULL);while (*src){count;}return count; }int main() {char arr1[] hello;const char* ps arr1;size_t len my_strlen(ps);printf(%zd\n,len); //%zd 或者 %u 打印 无符号整型return 0; }三、编程常见的错误 1、编译型错误语法错误 在编译期间产生的错误都是语法问题。 直接看错误提示信息双击解决问题。或者凭借经验就可以搞定。相对来说简单。 2、链接型错误 在链接期间产生的错误。 看错误提示信息主要在代码中找到错误信息中的标识符然后定位问题所在。 一般是 标识符名不存在 或者 拼写错误。 3、运行时错误 程序运行起来了但是结果不是我们想要的逻辑上出现问题。 借助调试逐步定位问题。最难搞。 四、做一个有心人积累排错经验。 做一个错题本将 调试的错误 都积累起来 微软雅黑字体 黑体 3号字 4号字 红色 绿色 蓝色
http://www.sczhlp.com/news/201811/

相关文章:

  • 广东手机网站建设费用沧州网站建设制作设计优化
  • 韶关建设局网站如何找专业的网站建设公司
  • fn网站不是做那么好吗秦皇岛网站设计制作
  • 珠宝网站开发网站建设的er图
  • 阿里巴巴网站建设教程做网站需要学些什么条件
  • 微信电影网站怎么做学广告设计要学多久
  • 做好我局门户网站建设工作杭州网站建设 网络服务
  • 高性能网站建设指南 书网页版视频怎么下载
  • 公司网站模板怎么写wordpress搭建主机
  • 牛网站送给做网站的锦旗语
  • 商务网站建设与维护徐州网站建设一薇
  • 做电影网站赚了几百万怎么申请自己的网络平台
  • 网站开发的晋升晋升空间路径wordpress前台版权
  • 网站制作ppt网站不备案怎么回事
  • 电影下载网站 怎么做收录查询api
  • 简述电子商务网站建设的基本要求怎么用flashfxp上传网站
  • 网站建设提升医院信息化水平整站seo优化公司
  • 可以自己做网站赚钱吗wordpress做多重筛选
  • 网站分析流程网站空间可以自己买吗
  • php网站建设网站网站404做多大
  • 网站设计 公司 长沙企业网站建设免备案
  • 广东官网网站建设企业新站突然网站停止收录
  • 西安在线网深圳搜狗seo
  • 网站单页在线制作软件网络营销是什么基础类型
  • .net网站方案seo推广内容
  • 烟台网站建设哪家专业做仪表宣传哪个网站好
  • 江苏天德建设工程有限公司网站整合营销传播策划方案
  • 网站,商城,app 建设wordpress简约高端企业通用产品
  • 工程行业招聘网站做淘宝的网站的多少钱
  • 在线教育网站策划方案抖抈短视频app下载安装