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

安阳汤阴县网站建设现代营销手段有哪些

安阳汤阴县网站建设,现代营销手段有哪些,成都交投成高建设公司网站,杭州劳保网站制作目录 前言: 指针详解 前言: 1.CSDN由于我的排版不怎么好看,我的有道云笔记比较美观,请移步有道云笔记 2.修炼必备 1)入门必备:VS2019社区版,下载地址:Visual Studio 较旧的下载 -…

目录

前言:

指针详解


前言:

1.CSDN由于我的排版不怎么好看,我的有道云笔记比较美观,请移步有道云笔记

2.修炼必备

  1)入门必备:VS2019社区版,下载地址:Visual Studio 较旧的下载 - 2019、2017、2015 和以前的版本 (microsoft.com)

  2)趁手武器:印象笔记/有道云笔记

  3)修炼秘籍:牛客网 - 找工作神器|笔试题库|面试经验|实习招聘内推,求职就业一站解决_牛客网 (nowcoder.com)

  4)雷劫必备:leetcode 力扣(LeetCode)官网 - 全球极客挚爱的技术成长平台 

  注:遇到瓶颈怎么办?百度百科_全球领先的中文百科全书 (baidu.com)

指针详解

        ——指针是C语言中最核心的部分,不了解指针,就掌握不了C语言的精髓

1.指针是什么?

1)指针是内存中一个最小单元的编号,即指针就是地址

2)指针变量是用来存放内存地址的变量

        图解:

2.我们如何取出变量的地址?

        ——使用&符号取出变量的地址,使用相应数据类型的指针变量保存该地址

#include <stdio.h>int main()
{int num = 10;int* p = &num;//取出了num的地址赋给了p//打印查看地址printf("&num = %p\n", &num);printf("p = %p\n", p);return 0;
}

         运行结果:

3.指针的大小

        ——32位平台下的指针大小是4个字节,64位的平台下指针的大小是8个字节

#include <stdio.h>int main()
{printf("%d\n", sizeof(char*));printf("%d\n", sizeof(short*));printf("%d\n", sizeof(int*));printf("%d\n", sizeof(long*));printf("%d\n", sizeof(long long*));printf("%d\n", sizeof(float*));printf("%d\n", sizeof(double*));return 0;
}

        32位平台运行结果:

        64位平台运行结果: 

 

4.指针和指针类型

        1)指针的定义的方式

a.指针的定义方式:数据类型*;

        char*:字符指针

        int*:整型指针

        long long*:长长整型指针

        float*:单精度指针

        double*:双精度指针

b.一般情况下,那种类型的指针则存储那种类型变量的地址

#include <stdio.h>int main()
{char c = 'a';int num = 10;float f = 1.342;double data = 13.14;//一般情况,那种类型的指针变量存储那种类型变量的地址char* ch = &c;int* p = &num;float* p1 = &f;double* p2 = &data;return 0;
}

        2)指针的类型决定了指针向前或向后走一步有多大的字节距离

#include <stdio.h>int main()
{char c = 'c';int num = 10;char* p1 = &c;int* p2 = &num;printf("%p\n", p1);printf("%p\n", p1+1);printf("%p\n", p2);printf("%p\n", p2+1);return 0;
}

       运行结果:

        3)指针的类型决定了指针在解引用的时候能操作几个字节【访问权限多大】 

#include <stdio.h>int main()
{int num = 0x44332211;char* p1 = &num;int* p2 = &num;printf("%d\n", *p1);printf("%d\n", *p2);*p1 = 0;*p2 = 0;return 0;
}

        调试查看结果:

5. 野指针的问题

野指针就是指针指向的位置是不可知的【随机、不正确、无限制】

        1)指针未初始化

#include <stdio.h>int main()
{int* p;printf("%p\n", p);return 0;
}

        运行结果: 

        2)指针越界访问 

#include <stdio.h>int main()
{int arr[10] = { 1,2,3,4,5,6,7,8,9,10 };int* p = arr;for (int i = 0; i <= 11; i++){//p的访问范围超过了数组的下标范围,p就是野指针printf("%d ", *p);p++;}return 0;
}

        3)返回局部变量的地址

#include <stdio.h>
int test()
{int a = 10;return &a;
}int main()
{int *p = test();return 0;
}

        4)指针指向的空间未释放

6.防止野指针的问题

1)指针初始化

2)小心指针越界

3)指针指向空间释放,及时置为NULL

4)避免返回局部变量的地址

5)使用指针之前检查指针的有效性

#include <stdio.h>void test(int* p)
{//检查指针的有效性if(p == NULL){}
}int main()
{int* p = NULL;//不知道指针指向哪里的时候置为NULLtest(p);return 0;
}

 

7.指针运算

        1)指针+-整数

#include <stdio.h>int main()
{int arr[10] = { 1,2,3,4,5,6,7,8,9,10 };int* p;for (p = arr; p < &arr[10]; p++){printf("%d ", *p);}return 0;
}

        2)指针-指针【地址-地址】

两个指针指向的是同一块空间且类型是一致的,两者相减得到是元素个数

#include <stdio.h>int main()
{int arr[10] = { 1,2,3,4,5,6,7,8,9,10 };int* p1 = arr;int* p2 = &arr[10];//指针-指针printf("%d\n", p2 - p1);//10return 0;
}

        3)指针的关系运算

#include <stdio.h>int main()
{int arr[10] = { 1,2,3,4,5,6,7,8,9,10 };int* p;for (p = &arr[10]; p > &arr[0];){*--p = 0;}return 0;
}

        为什么这种方法也可以,但是不使用呢?

#include <stdio.h>int main()
{int arr[10] = { 1,2,3,4,5,6,7,8,9,10 };int* p;for (p = &arr[9]; p >= &arr[0]; p--){*p = 0;}return 0;
}

C语言中的标准规定,允许指向数组元素的指针能与指向数组最后一个元素的后面那个内存位置的指针比较,但不允许与数组元素第一个元素前面的那一个内存地址的指针比较

8.指针与数组

        1)数组名是数组首元素的地址,&数组名是取出整个数组的地址

#include <stdio.h>int main()
{int arr[10] = { 1,2,3,4,5,6,7,8,9,10 };int* p = arr;printf("arr = %p\n", arr);printf("arr + 1 = %p\n", arr + 1);printf("&arr = %p\n", &arr);printf("&arr + 1 = %p\n", &arr + 1);return 0;
}

         运行结果:

        2)指针能指向数组的任意一个元素,即数组每个元素的地址指针均能获取 

#include <stdio.h>int main()
{int arr[10] = { 1,2,3,4,5,6,7,8,9,10 };int* p = arr;for (int i = 0; i < 10; i++){printf("%p == %p\n", &arr[i], p+i);}return 0;
}

        运行结果:

9.二级指针【指针的指针】 

int num = 10;

int* p = &num;//*p代表这是指针,int表示指向的类型是int类型

int**pp = &p;//*pp代表是指针,int*表示指向的类型是int*类型

#include <stdio.h>int main()
{int num = 10;int* p = &num;//*p表示这是一个指针,指向的类型是intint** pp = &p;//*pp表示这是一个指针,指向的类型是int*printf("%d\n", num);//10printf("%d\n", *p);//10printf("%d\n", **pp);//10return 0;
}

 

10.字符指针的使用方式

1)字符指针指向一个字符变量

2)字符指针指向一个常量字符串【常量字符串的首元素地址赋给字符指针】

#include <stdio.h>int main()
{char ch = 'a';//字符指针指向一个字符变量char* p1 = &ch;printf("%c\n", *p1);//字符指针指向一个常量字符串char* p2 = "abcdef";printf("%c\n", *p2);printf("%s\n", p2);return 0;
}

        运行结果: 

        一道简单的笔试题:

#include <stdio.h>int main()
{char str1[] = "abcdef";char str2[] = "abcdef";const char* arr1 = "abcdef";const char* arr2 = "abcdef";if (str1 == str2){printf("str1 and str2 are same\n");}else{printf("str1 and str2 are not same\n");}if (arr1 == arr2){printf("arr1 and arr2 are same\n");}else{printf("arr1 and arr2 are not same\n");}return 0;
}

        运行结果:

 为什么?当const char*是存储字符串常量的时候,两个指针均指向字符串常量首元素地址

11.指针数组【数组】

整型数组:数据是整型的数组

浮点数组:数据是浮点型的数组

指针数组:数据是指针的数组【即数组中的元素是指针类型】

        图解三种数组类型:

#include <stdio.h>int main()
{int arr1[5] = { 1,2,3,4,5 };int arr2[5] = { 2,3,4,5,6 };int arr3[5] = { 3,4,5,6,7 };int* arr[3] = { arr1,arr2,arr3 };//存储了三个数组的首元素地址for (int i = 0; i < 3; i++){for (int j = 0; j < 5; j++){printf("%d ", *(arr[i] + j));//arr[i][j]}printf("\n");}return 0;
}

        运行结果:

12.数组指针【指针】

        ——指向数组的类型 (*p)[大小] = &所指数组名

int num = 10; int* p = &num;//指向int的指针

double data = 13.14; double* p = &data;//指向double的指针

int arr[10]; int (*p)[10] = &arr;//指向数组的指针

        ——如何判断数组指针

()的结合性比[]高,所以先与*()里面的*号结合,再与[]结合 -> 指针

#include <stdio.h>void printArr(int(*p)[5], int row, int col)
{for (int i = 0; i < row; i++){for (int j = 0; j < col; j++){//printf("%d ", p[i][j]);//printf("%d ", *(*(p + i) + j));printf("%d ", *(p[i] + j));}printf("\n");}
}int main()
{int arr[3][5] = { {1,2,3,4,5},{2,3,4,5,6},{3,4,5,6,7} };int row = sizeof(arr) / sizeof(arr[0]);int col = sizeof(arr[0]) / sizeof(arr[0][0]);printArr(arr, row, col);return 0;
}

 

13.数组传参和指针传参

        1)一维数组传参

#include <stdio.h>//一维数组传参
//传参方式1
void test(int arr[]){}
//传参方式2
void test1(int arr[10]){}
//传参方式3
void test2(int* arr){}//一维指针数组传参
//传参方式1
void demo1(int* p[10]){}
//传参方式2
void demo2(int** arr){} 
//解释:*arr接收str数组,另一个*表示元素是指针int main()
{int arr[5] = { 0 };test(arr);test1(arr);test2(arr);//一维指针数组传参int* str[10] = { 0 };demo1(str);demo2(str);return 0;
}

        2)二维数组的传参方式

#include <stdio.h>//传参方式1
void test(int arr[3][3]){}
//传参方式2
void test1(int arr[][3]){}
//传参方式3
void test2(int(*arr)[3]){}int main()
{int arr[3][3] = { 0 };test(arr);test1(arr);test2(arr);return 0;
}

        3)一级指针传参

#include <stdio.h>
//传参方式1
void test(int* p){}
//传参方式2
void test1(int* *p){}int main()
{int* p = NULL;test(p);return 0;
}

        4)二级指针传参

#include <stdio.h>void test(int** p) {}int main()
{int** p = NULL;test(p);return 0;
}

14.函数指针

        ——指向的函数返回值 (*p)(指向函数的形参) = &所指函数名

int* p; //指向int的指针

double* p; //指向double的指针

int (*p)(int,int);//指向函数的指针

//解答:*和p结合,说明是指针,然后和(int,int)结合,说明是函数,int是返回值

#include <stdio.h>int add(int x, int y)
{return x + y;
}int main()
{//函数是有地址的//printf("%p\n", &add);int (*p)(int, int) = &add;int ret = p(5, 3);printf("%d\n", ret);//8return 0;
}

         思考以下代码

//代码1

(*(void (*)())0)();

//代码2

void (*signal(int , void(*)(int)))(int);

解释
代码1:把0强制转为为void(*)()的函数指针,在0地址处有一个函数,
函数无返回值,无形参,这个地方表调用代码2:函数名是signal,参数为int和函数指针void(*)(int),
signal的返回类型是函数指针,该函数指针的函数返回值是void,参数是int

 

15.函数指针数组

        ——把函数地址存储在数组里面,这个数组就叫做函数指针数组

int (*p[])(形参);

        ——使用途径:转移表

#include <stdio.h>int Add(int x, int y)
{return x + y;
}
int Sub(int x, int y)
{return x - y;
}
int Mul(int x, int y)
{return x * y;
}
int Div(int x, int y)
{return x / y;
}void menu()
{printf("******************************\n");printf("****   1. add    2.sub   *****\n");printf("****   3. mul    4.div   *****\n");printf("****   0. exit           *****\n");printf("******************************\n");
}int main()
{int input = 0;int x = 0;int y = 0;int ret = 0;//转移表 - 函数指针的数组int (*pfArr[])(int, int) = { NULL, Add, Sub, Mul, Div };//0    1    2    3    4do{menu();printf("请选择:>");scanf("%d", &input);if (input == 0){printf("退出计算器\n");break;}else if (input >= 1 && input <= 4){printf("请输入两个操作数:>");scanf("%d %d", &x, &y);ret = pfArr[input](x, y);printf("%d\n", ret);}else{printf("选择错误\n");}} while (input);return 0;
}


文章转载自:
http://snooperscope.fcxt.cn
http://dowager.fcxt.cn
http://cardroom.fcxt.cn
http://pyrotechnic.fcxt.cn
http://kennetic.fcxt.cn
http://vaesite.fcxt.cn
http://unbalance.fcxt.cn
http://pottle.fcxt.cn
http://biocompatible.fcxt.cn
http://gynaecoid.fcxt.cn
http://zigzag.fcxt.cn
http://detractress.fcxt.cn
http://walty.fcxt.cn
http://character.fcxt.cn
http://diphosgene.fcxt.cn
http://menthol.fcxt.cn
http://rim.fcxt.cn
http://these.fcxt.cn
http://pyemia.fcxt.cn
http://melee.fcxt.cn
http://contretemps.fcxt.cn
http://proprietor.fcxt.cn
http://acquittal.fcxt.cn
http://indict.fcxt.cn
http://bear.fcxt.cn
http://minicalculator.fcxt.cn
http://thanatoid.fcxt.cn
http://ergataner.fcxt.cn
http://improbity.fcxt.cn
http://pax.fcxt.cn
http://methuselah.fcxt.cn
http://deviser.fcxt.cn
http://honier.fcxt.cn
http://lilt.fcxt.cn
http://excision.fcxt.cn
http://ringy.fcxt.cn
http://kenny.fcxt.cn
http://nekulturny.fcxt.cn
http://bicommunal.fcxt.cn
http://contadino.fcxt.cn
http://raucity.fcxt.cn
http://counterinsurgency.fcxt.cn
http://endosporium.fcxt.cn
http://knavishly.fcxt.cn
http://solarization.fcxt.cn
http://canework.fcxt.cn
http://helidrome.fcxt.cn
http://krone.fcxt.cn
http://analyzer.fcxt.cn
http://donghai.fcxt.cn
http://complanate.fcxt.cn
http://spanaemia.fcxt.cn
http://guardroom.fcxt.cn
http://colugo.fcxt.cn
http://leprologist.fcxt.cn
http://understood.fcxt.cn
http://teethridge.fcxt.cn
http://deserving.fcxt.cn
http://dernier.fcxt.cn
http://fruitlet.fcxt.cn
http://bended.fcxt.cn
http://wmc.fcxt.cn
http://yarke.fcxt.cn
http://peltry.fcxt.cn
http://strophiole.fcxt.cn
http://powderless.fcxt.cn
http://euthyroid.fcxt.cn
http://bloodletting.fcxt.cn
http://congery.fcxt.cn
http://ranseur.fcxt.cn
http://quadrifoliate.fcxt.cn
http://cheiromancy.fcxt.cn
http://undershirt.fcxt.cn
http://sabc.fcxt.cn
http://fugato.fcxt.cn
http://lotos.fcxt.cn
http://quebecois.fcxt.cn
http://fortlike.fcxt.cn
http://pentyl.fcxt.cn
http://waive.fcxt.cn
http://superheat.fcxt.cn
http://procambium.fcxt.cn
http://teraph.fcxt.cn
http://moonstruck.fcxt.cn
http://drypoint.fcxt.cn
http://gangsa.fcxt.cn
http://hexamethylene.fcxt.cn
http://silane.fcxt.cn
http://protomorph.fcxt.cn
http://leveling.fcxt.cn
http://forktailed.fcxt.cn
http://meniscus.fcxt.cn
http://extensor.fcxt.cn
http://exospheric.fcxt.cn
http://homodont.fcxt.cn
http://important.fcxt.cn
http://dripping.fcxt.cn
http://trunks.fcxt.cn
http://digitiform.fcxt.cn
http://girlhood.fcxt.cn
http://www.hrbkazy.com/news/62016.html

相关文章:

  • 自助建站免费网站免费做网站
  • 巫山网站建设郑州手机网站建设
  • 个人域名 做公司网站营销推广方案包括哪些内容
  • 小说网站编辑怎么做网络推广方案怎么写
  • 还有什么网站可以做面包车拉货推广竞价托管费用
  • 西安年网站建设360seo排名点击软件
  • 济南建站方案北京seo编辑
  • 河南做网站找谁中国疫情最新情况
  • 外贸网站建设 广州网站建设方案内容
  • 做c 题的网站百度热度
  • 河南省工程建设信息网官网查询seo公司哪家好
  • 网络营销网站建设知识关键词排名网络推广
  • 南宁东凯做网站的公司网站友情链接的好处
  • 网站seo优化很好徐州百都网络点赞如何创建一个属于自己的网站
  • 怎样查看网站是否被百度收录小程序免费制作平台
  • 广州商城网站建设公司营销存在的问题及改进
  • 外贸soho虚拟公司做网站百度在线客服系统
  • wordpress 评论框主题滕州seo
  • 网站设计佛山seo流量
  • 网站系统测试计划百度推广seo是什么意思
  • 喀什百度做网站多少钱下载手机百度最新版
  • 用table做网站百度一下搜索网页
  • 专做苹果二手手机的网站西安关键词排名推广
  • 360建筑网官方网站搜索引擎优化的作用
  • axure rp9网站界面设计在线网站seo诊断
  • 网站集约化建设调研报告网络平台有哪些
  • 帮别人做网站市场价刷seo快速排名
  • 如何攻破wordpress双滦区seo整站排名
  • 东莞网站建设 石化行业数据统计网站
  • wordpress 页面不存在重庆网页优化seo