strlen(x) 返回 size_t 类型,size_t是 unsigned int 类型,所以 strlen(x)-strlen(y) 返回 unsigned int 始终 >=0

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <stdio.h>
#include <string.h>
void main()
{
char *sa="sdhshdh";
char *sb="cdehhhhsdssssd";
printf("%d , %d \n",strlen(sa),strlen(sb));
     
if(strlen(sa)-strlen(sb)>=0)
{
    printf("run 1\n");
}
}

如果不加 include <string.h>头文件

1
2
3
4
5
6
7
8
9
10
11
12
#include <stdio.h>
void main()
{
char *sa="sdhshdh";
char *sb="cdehhhhsdssssd";
printf("%d , %d \n",strlen(sa),strlen(sb));
     
if(strlen(sa)-strlen(sb)>=0)
{
    printf("run 1\n");
}
}
1
warning C4013: 'strlen' undefined; assuming extern returning int

2可变参数列表

要用到 stdarg 宏

3数组名

数组名是一个常数指针,在两种情况下数组名不用 指针常数表示

  1. sizeof sizeof返回整数数组的长度

  2. & 是指向数组的指针,而不是指向指针常量的指针。

1
2
3
4
5
6
#include <stdio.h>
void main()
{
int a[4]={1,1,1,1};
printf("%d \n",sizeof(a));
}

并不是 4(指针常量的长度)

1
2
3
4
5
6
7
8
#include <stdio.h>
void main()
{
int a[4]={1,1,1,1};
int *b;
b=a;
printf("%d \n",b[2]);
}

数组对数组赋值的方法:利用循环(已经有了数组,对数组进行更新)

利用指针变量。

不能这样写

1
2
3
int a[4]={1,1,1,1};
int b[4];
b=a;

因为 b为指针常量不能赋值。

4下标引用,和间接引用

1
2
3
4
5
6
7
#include <stdio.h>
void main()
{
int a[4]={1,2,3,4};
printf("%d \n",*(a+2));
printf("%d \n",a[2]);
}

负值下标

1
2
3
4
5
6
7
8
9
#include <stdio.h>
void main()
{
int a[4]={1,2,3,4};
int *p;
p=a+2;
printf("%d \n",*(a+1));
printf("%d \n",p[-1]);
}

下标引用可以作用于任何指针

1
2
3
4
5
6
7
8
9
#include <stdio.h>
#include <math.h>
void main()
{
int a[4]={1,2,3,4};
printf("a[0]->%d \n",a[0]);
printf("1[a]->%d \n",1[a]);
printf("a[1]->%d \n",a[1]);
}

c 函数及指针学习 3的更多相关文章

  1. C函数及指针学习1

    1 大段程序注释的方法 #if 0#endif 2三字母词 以两个问号 开始的都要注意 3 字面值(常量) 在整型号字面值后加 字符L (long),U(unsigned)说明字符常量 为长整型 或( ...

  2. c 函数及指针学习 10

    标准库函数 1算数运算stdlib.h 2随机数stdlib.h 3字符串转化stdlib.h 4数学函数 math.h 5日期和时间 time.h 6信号 signal.h 7打印可变参数列表std ...

  3. c 函数及指针学习 9

    指针的高级应用 处理命令行参数 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 #include <stdio.h>   int main(int ar ...

  4. c 函数及指针学习 7

    1.结构的存储分配 1 2 printf("%d \n",sizeof(char)); printf("%d \n",sizeof(int)); int 类型为 ...

  5. c 函数及指针学习 5

    聚合数据类型 能够同时存储超过一个的单独数据. c语言提供了数组和结构体. 1. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 #include <stdio.h> # ...

  6. c 函数及指针学习 4

    1数组和指针声明的差别 声明数组:为数组分配内存,为数组名分配内存(指针常量 4个字节) 指针:为指针分配内存(指针变量 4个字节) 1 2 3 4 5 6 7 8 9 10 #include < ...

  7. C函数及指针学习2

    1.break  永久终止循环,continue 结束当前循环 2.switch 每个case标签要有唯一值,(且为常量或常量表达式) 不加break 时执行流会贯穿整个case 标签 3 赋值操作符 ...

  8. c 函数及指针学习 8

    联合体 1 2 3 4 5 6 7 8 9 10 11 12 13 #include <stdio.h>   union sa     {     double a;     int b; ...

  9. c 函数及指针学习 6

    不完整声明 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 /* 方法一   */ struct tag_a{ ...

随机推荐

  1. ASP.NET MVC学习之路由篇(1)

    1.基本路由 RouteConfig.cs: 1 public class RouteConfig 2 { 3 public static void RegisterRoutes(RouteColle ...

  2. 【第40套模拟题】【noip2011_mayan】解题报告【map】【数论】【dfs】

    目录:1.潜伏者 [map] 2.Hankson的趣味题[数论]3.mayan游戏[dfs] 题目: 1. 潜伏者(spy.pas/c/cpp)[问题描述]R 国和S 国正陷入战火之中,双方都互派间谍 ...

  3. superobject中 JavaToDelphiDateTime的使用

    procedure TForm1.FormCreate(Sender: TObject); var n: TDateTime; i64: Int64; s: Integer; begin Memo1. ...

  4. Linux - gcc和g++的区别

    一般linux系统都自带了gcc编译器的,你可以用你的安装光盘去安装,如果你是觉得自带的gcc版本太低了,可以去gcc的官方网站可以下载到,编译需要很长的时间,如果你只编译C或者C++可以只下载gcc ...

  5. 哪些字符需要urlencode编码?具体怎么处理?

    哪些字符需要urlencode编码?具体怎么处理? JS用escape()/encodeURI()/encodeURIComponent()方法编码,用unescape()/decodeURI()/e ...

  6. Map学习

    1.Query Operations(查询操作) int size();boolean isEmpty(); boolean containsKey(Object key);boolean conta ...

  7. matlab 画框(三) 画框并保存图像

    initstate = [x y w h];%-----------------------------------------Show the tracking resultimshow(uint8 ...

  8. struts2和servlet同时用(访问servlet时被struts2过滤器拦截问题的解决)

    在同一个项目中间,如果既用到servlet有用了struts2的框架,运行项目时可能无法正常使用servlet,原因是在配置struts2的核心控制器时<url-pattern>/*< ...

  9. alloc和初始化的定义

    1.alloc是为原始实例进行分配内存,但是还不能使用 2.初始化的作用就是将一个对象的初始状态(即它的实例变量和属性)设定为合理的值,然后返回对象.它的目的就是返回一个有用的值

  10. sphinx 全配置

    ## 数据源src1 source src1 { ## 说明数据源的类型.数据源的类型可以是:mysql,pgsql,mssql,xmlpipe,odbc,python ## 有人会奇怪,python ...