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. C#编程

    C#最完整的webservice实例 http://fyinthesky.blog.163.com/blog/static/3555251720110115227337/ C# WinForm 实践开 ...

  2. windbg调试C#代码(一)

    用windbg调试C#代码是比较麻烦的,因为windbg是针对OS层级的,而C#被CLR隔了一层,很多原生的命令如查看局部变量dv.查看变量类型dt等在CLR的环境中都不能用了.必须使用针对CLR的扩 ...

  3. 从协议VersionedProtocol开始2——ClientDatanodeProtocol和InterDatanodeProtocol

    1.首先,我看的是hadoop1.2.1 这个里边,有点奇怪ClientDatanodeProtocol的versionID是4,但是InterDatanodeProtocol的versionID是3 ...

  4. c#读取文本文档实践1-File.ReadAllLines()

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.I ...

  5. C语言之强制类型转换与指针--#define DIR *((volatile unsigned int *) 0x0022)

    强制类型转换形式:(类型说明符) (表达式) 举例说明:1) int a; a = (int)1.9; 2)char *b; int *p; p = (int *) b; //将b的值强制转换为指向整 ...

  6. linux下获取帮助

    -h --help man 代號 代表內容 使用者在shell中可以操作的指令或可执行档 系統核心可呼叫的函数与工具等 一些常用的函数(function)与函数库(library),大部分是C的函数库 ...

  7. NSString的几种常用方法

    NSString的几种常用方法   要把 “2011-11-29” 改写成 “2011/11/29”一开始想用ios的时间格式,后来用NSString的方法搞定. [string stringByRe ...

  8. spark与Hadoop区别

    2分钟读懂Hadoop和Spark的异同 2016.01.25 11:15:59 来源:51cto作者:51cto ( 0 条评论 )   谈到大数据,相信大家对Hadoop和Apache Spark ...

  9. javascript笔记4-函数表达式

    一般形式的创建函数,在执行代码之前会先读取函数声明,所以可以把函数声明写在函数调用的下面: sayHi(); function sayHi(){ alert("Hi!"); } 使 ...

  10. 我与python3擦肩而过(二)—— csv文件头哪去啦?

    在看Python Data Visualization Cookbook 这本书(基于python2),开始时读取csv文件头的时候出现问题.查了资料,又是python3的问题,从这个链接找到答案. ...