C进阶 部分内存 指针数组 数组指针

#include <stdio.h>
#include <stdlib.h>

//内存
#if 0
int main(){
	char a= - 128;
	char b = -127;
	char c = -126;
	printf("%d %d %d\n", a, b, c);
	printf("%u %u %u\n", a, b, c);
	system("pause");
	return 0;
}
#endif
#if 0
int main(){
	char a = -1;
	signed b = -1;
	unsigned c = -1;
	printf("%d,%d,%d\n", a, b, c);
	printf("%u,%u,%u\n", a, b, c);
	system("pause");
	return 0;
}
#endif

//数组指针
#if 0
//qsort->排序  cmp->回调函数
int cmp(const void*p1, const void*p2){
	return (*(int *)p1 - *(int *)p2);
}
int main(){
	int arr[] = { 6, 5, 7, 8, 9, 0, 1, 2, 3, 4, 5 };
	int n = sizeof(arr) / sizeof(arr[0]);
	int i;
	qsort(arr, n, sizeof(int), cmp);
	for (i = 0; i < n; ++i){
		printf("%d ", arr[i]);
	}
	system("pause");
	return 0;
}
#endif
#if 0
int main(){
	int arr[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
	int(*p)[10];
	p = &arr;
	system("pause");
	return 0;
}
#endif

//指针数组
//数组名不能在左值
//int a[3][4]
//a   ->(int*)[4]
//a[i]      ->int *
//a[i][j]  ->int
#if 0
int main(){
	char(*name)[5] = { "lili", "a", "fasfafaffage", "fafaetaac", "fayeyuyn" };
	//数组指针  //错误:因为name为指向一个存放五个字符的数组指针,
	                  //本质还是指针,且指向的这个数组里面只能含有
	                  //五个字符。
	char *name[5] = { "lili", "asdafafa", "fasfafaffage", "fafaetaac", "fayeyuyn" };
	//指针数组
	system("pause");
	return 0;
}
#endif
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值