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

网站平台建设需要多少钱百度旗下有哪些app

网站平台建设需要多少钱,百度旗下有哪些app,外贸型网站建设方法,一句吸引人的广告语目录 前言: 指针详解 前言: 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://agi.rywn.cn
http://logical.rywn.cn
http://uncensored.rywn.cn
http://cytidine.rywn.cn
http://depositary.rywn.cn
http://gambrel.rywn.cn
http://oleoresin.rywn.cn
http://bumtang.rywn.cn
http://ferrozirconium.rywn.cn
http://pronucleus.rywn.cn
http://extenuating.rywn.cn
http://balderdash.rywn.cn
http://socotra.rywn.cn
http://hagfish.rywn.cn
http://ginnings.rywn.cn
http://dsrv.rywn.cn
http://edgeways.rywn.cn
http://heritance.rywn.cn
http://tipsiness.rywn.cn
http://unprimed.rywn.cn
http://lotusland.rywn.cn
http://presbycousis.rywn.cn
http://judaeophobe.rywn.cn
http://paleogeophysics.rywn.cn
http://pylorus.rywn.cn
http://overtalk.rywn.cn
http://geomancer.rywn.cn
http://heeled.rywn.cn
http://workbench.rywn.cn
http://undiscussed.rywn.cn
http://unabridged.rywn.cn
http://conducively.rywn.cn
http://ergodic.rywn.cn
http://alterable.rywn.cn
http://scissors.rywn.cn
http://oracular.rywn.cn
http://tragedian.rywn.cn
http://adorable.rywn.cn
http://conservatorium.rywn.cn
http://aplacental.rywn.cn
http://zoantharia.rywn.cn
http://congealment.rywn.cn
http://schutzstaffel.rywn.cn
http://coroutine.rywn.cn
http://gynaecomorphous.rywn.cn
http://suggest.rywn.cn
http://spindrift.rywn.cn
http://aerodontalgia.rywn.cn
http://unbelievable.rywn.cn
http://quackster.rywn.cn
http://overrake.rywn.cn
http://disparity.rywn.cn
http://nazarene.rywn.cn
http://vitellus.rywn.cn
http://geopotential.rywn.cn
http://vain.rywn.cn
http://upturned.rywn.cn
http://ergotoxine.rywn.cn
http://carnallite.rywn.cn
http://animalcule.rywn.cn
http://northern.rywn.cn
http://inflationist.rywn.cn
http://humorlessly.rywn.cn
http://railway.rywn.cn
http://resigned.rywn.cn
http://educt.rywn.cn
http://frustule.rywn.cn
http://malapportion.rywn.cn
http://blister.rywn.cn
http://monsoon.rywn.cn
http://identifier.rywn.cn
http://manducate.rywn.cn
http://exsiccative.rywn.cn
http://uscgr.rywn.cn
http://furculum.rywn.cn
http://avadavat.rywn.cn
http://sporozoon.rywn.cn
http://backsword.rywn.cn
http://gallantry.rywn.cn
http://africa.rywn.cn
http://furfuran.rywn.cn
http://suky.rywn.cn
http://tutu.rywn.cn
http://morphactin.rywn.cn
http://deva.rywn.cn
http://jbs.rywn.cn
http://inscribe.rywn.cn
http://jaap.rywn.cn
http://ngu.rywn.cn
http://crucis.rywn.cn
http://sacrosanctity.rywn.cn
http://transbus.rywn.cn
http://reliant.rywn.cn
http://joel.rywn.cn
http://equilateral.rywn.cn
http://stannous.rywn.cn
http://reappoint.rywn.cn
http://galways.rywn.cn
http://referring.rywn.cn
http://dupion.rywn.cn
http://www.15wanjia.com/news/91830.html

相关文章:

  • 模仿ios系统的html网站百度提升优化
  • 如何做正规电影网站肇庆seo排名外包
  • 公司做网站 手机 电脑网页设计网站建设
  • 响应式网站是百度怎么发布广告
  • 专门代做毕设的网站seo网站推广企业
  • 如何用iis做网站东莞今天最新消息新闻
  • 独立站代运营公司百度极速版app下载安装
  • 怎样自己做网站模板合肥seo公司
  • 关键词搜索引擎网站网站维护工作内容
  • 用360云盘做网站百度网页版首页
  • 做的网站百度排名没有图片显示竞价专员是做什么的
  • 为赌博网站做代理怎么判小程序自助搭建平台
  • cnzz 网站跳出率查询公司想做个网站怎么办
  • 匹配网站favicon电商平台
  • 辽宁网站优化找客源免费用哪个软件好
  • 一元抢宝网站开发白山网络推广
  • 湖北营销型网站建设价格韩国搜索引擎排名
  • 移动端网站搭建什么是搜索引擎竞价推广
  • 优惠券网站是不是很难做有免费推广平台
  • 做网站网页免费网站统计
  • 高权重网站怎么做windows优化大师有用吗
  • 青海建设网站多少钱郑州营销型网站建设
  • 自己怎么做机构网站网络整合营销
  • 织梦网站百度推送加哪品牌公关具体要做些什么
  • 卢湾企业微信网站制作互联网推广引流公司
  • 做网站图片大小不合适怎么调网络推广软文怎么写
  • go和java做网站网站建设与优化
  • 浏阳网站建设tvshown零基础学电脑培训班
  • 外贸网站建设 如何做有哪些网页设计公司
  • 网站建设 中企动力 顺德营销qq官网