c 函数及指针学习 3
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数组名
数组名是一个常数指针,在两种情况下数组名不用 指针常数表示
sizeof sizeof返回整数数组的长度
& 是指向数组的指针,而不是指向指针常量的指针。
|
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的更多相关文章
- C函数及指针学习1
1 大段程序注释的方法 #if 0#endif 2三字母词 以两个问号 开始的都要注意 3 字面值(常量) 在整型号字面值后加 字符L (long),U(unsigned)说明字符常量 为长整型 或( ...
- c 函数及指针学习 10
标准库函数 1算数运算stdlib.h 2随机数stdlib.h 3字符串转化stdlib.h 4数学函数 math.h 5日期和时间 time.h 6信号 signal.h 7打印可变参数列表std ...
- 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 ...
- c 函数及指针学习 7
1.结构的存储分配 1 2 printf("%d \n",sizeof(char)); printf("%d \n",sizeof(int)); int 类型为 ...
- c 函数及指针学习 5
聚合数据类型 能够同时存储超过一个的单独数据. c语言提供了数组和结构体. 1. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 #include <stdio.h> # ...
- c 函数及指针学习 4
1数组和指针声明的差别 声明数组:为数组分配内存,为数组名分配内存(指针常量 4个字节) 指针:为指针分配内存(指针变量 4个字节) 1 2 3 4 5 6 7 8 9 10 #include < ...
- C函数及指针学习2
1.break 永久终止循环,continue 结束当前循环 2.switch 每个case标签要有唯一值,(且为常量或常量表达式) 不加break 时执行流会贯穿整个case 标签 3 赋值操作符 ...
- c 函数及指针学习 8
联合体 1 2 3 4 5 6 7 8 9 10 11 12 13 #include <stdio.h> union sa { double a; int b; ...
- 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{ ...
随机推荐
- Exif的Orientation信息说明
EXIF Orientation 参数让你随便照像但都可以看到正确方向的照片而无需手动旋转(前提要图片浏览器支持,Windows 自带的不支持) 这个参数在佳能.尼康相机照的照片是自带的,但我的奥林巴 ...
- MATLAB 函数
MATLAB函数大全 1.常见 http://wenku.baidu.com/link?url=tPpwD7Ox_1sG-SQv_XdYszBAPY9LX_Zb_dde_5JeOiu7RwN_i14X ...
- Struts2 的验证
概述 一个健壮的 web 应用程序必须确保用户输入是合法.有效的. Struts2 的输入验证 –基于 XWork Validation Framework 的声明式验证:Struts2 提供了一些基 ...
- RPI学习--WebCam_mplayer
1,安装mplayer $ sudo apt-get install mplayer 2,运行 $ sudo mplayer tv:// 有时会秀逗,绿屏,多试几下就好了,情况未知
- putty基本操作
1,进入全屏 标题栏右键,菜单中就有full screen选项. 2,退出全屏 鼠标移到左上角,单击鼠标左键,就会跳出菜单,full screen勾去掉. 3,从putty中复制内容到剪切板 鼠标左键 ...
- IE和火狐 差异
1.JavaScript中 1)IE和FireFox中childNodes的差别: <head> <script type="text/javascript"&g ...
- Helloworld程序的创建以及配置文件的讲解
创建项目. create Project 选择创建的Project类别以及使用的SDK,可能SDK需要配置或者修改配置. 这个页面是问你是否使用模板创建. Command Line App 会自动创建 ...
- Installing Cygwin and Starting the SSH Daemon
This chapter explains how to install Cygwin and start the SSH daemon on Microsoft Windows hosts. Thi ...
- 一个基于atomic的卖票测试
package testAtomic; import java.util.concurrent.atomic.AtomicInteger; import sun.security.krb5.inter ...
- mysql批量写入
MySQL批量写入语法是: INSERT INTO table (field1,field2,field3) VALUES (“a”,”b”,”c”), (“a1”,”b1”,”c1”),(“a2”, ...