上一页 1 ··· 310 311 312 313 314 315 316 317 318 ··· 407 下一页
摘要: c语言中显示字符串数组的长度(数组实现的字符串数组和指针实现的字符串数组) 1、 #include <stdio.h> int main(void) { char x[][128] = {"aaa","bb","cccccc","d","eee"}; char *y[] = {"11111","22 阅读全文
posted @ 2021-05-31 11:01 小鲨鱼2018 阅读(784) 评论(0) 推荐(0)
摘要: c语言中判断字符串的长度,利用数组和利用指针。 1、利用数组。 #include <stdio.h> int len(const char x[]) { int len = 0; while(x[len]) len++; return len; } int main(void) { char str 阅读全文
posted @ 2021-05-31 10:55 小鲨鱼2018 阅读(1935) 评论(0) 推荐(0)
摘要: 1、 #include <stdio.h> int main(void) { int i; char a[][5] = {"LISP","C","Ada"}; char *p[] = {"PAUL","X","MAC"}; printf("sizeof(a) = %u\n", sizeof(a)); 阅读全文
posted @ 2021-05-31 09:39 小鲨鱼2018 阅读(72) 评论(0) 推荐(0)
摘要: 1、 #include <stdio.h> int main(void) { int i; char a[][5] = {"LISP","C","Ada"}; char *p[] = {"PAUL","X","MAC"}; int j = 0; while(1) { int k = 0; while 阅读全文
posted @ 2021-05-30 23:33 小鲨鱼2018 阅读(57) 评论(0) 推荐(0)
摘要: 1、 #include <stdio.h> int main(void) { char *p = "123"; printf("p = %s\n", p); p = "456"; printf("p = %s\n", p); return 0; } ↓ #include <stdio.h> int 阅读全文
posted @ 2021-05-30 22:12 小鲨鱼2018 阅读(59) 评论(0) 推荐(0)
摘要: 用数组实现的字符串和用指针实现的字符串。 1、 #include <stdio.h> int main(void) { char str[] = "abc"; //数组实现的字符串,str为数组名,为指向数组起始元素的指针,相当于“a”的指针。 char *ptr = "123"; //指针实现的字 阅读全文
posted @ 2021-05-30 21:44 小鲨鱼2018 阅读(253) 评论(0) 推荐(0)
摘要: 1、 #include <stdio.h> void ary_set(int x[], int n, int val) { int i; for(i = 0; i < n; i++) { x[i] = val; } } int main(void) { int i; int a[5] = {1, 2 阅读全文
posted @ 2021-05-30 18:36 小鲨鱼2018 阅读(99) 评论(0) 推荐(0)
摘要: 1、 #include <stdio.h> void assign1(int x[], int n)//函数间数组的传递是以数组第一个元素的指针的形式传递的,因此形参变为指向数组第一个元素的指针,形参和数组本身的行为一样。 { int i; for(i = 0; i < n; i++) { x[i] 阅读全文
posted @ 2021-05-30 18:27 小鲨鱼2018 阅读(98) 评论(0) 推荐(0)
摘要: 1、函数间数组的传递是以指向第一个元素的指针的形式进行的,应为数组名会被解释为指向数组第一个元素的指针,形参部分的指针变量被赋值为数组的第一个元素 的指针时,指针变量指向数组的一个元素,因此指针变量的行为和传入的数组一样。 #include <stdio.h> void assign(int x[] 阅读全文
posted @ 2021-05-30 18:15 小鲨鱼2018 阅读(423) 评论(0) 推荐(0)
摘要: 对于数组a[n], 当p为数组的起始元素的指针时, 即 p = a = &a[0]时, p + i = a[i], &p[i] = &a[i] , a[i] = p[i], *(a + i) = *(p + i), 也就是说当p为数组的起始 元素的指针时,p的行为和数组本身是一样的。(原因: p为数 阅读全文
posted @ 2021-05-30 17:28 小鲨鱼2018 阅读(120) 评论(0) 推荐(0)
上一页 1 ··· 310 311 312 313 314 315 316 317 318 ··· 407 下一页