上一页 1 ··· 311 312 313 314 315 316 317 318 319 ··· 407 下一页
摘要: 当指针p声明为数组名a时, 则有 p + i = &a[i], 也就是说p + i是首个元素之后的第i个元素的指针。 1、 #include <stdio.h> int main(void) { int i; int a[5]; int *p = a; for(i = 0; i < 5; i++) 阅读全文
posted @ 2021-05-30 16:59 小鲨鱼2018 阅读(222) 评论(0) 推荐(0)
摘要: 1、三个值升序 #include <stdio.h> void swap(int *x, int *y) { int tmp = *x; *x = *y; *y = tmp; } void sort(int *i, int *j, int *k) { if(*i > *j) swap(i, j); 阅读全文
posted @ 2021-05-30 16:12 小鲨鱼2018 阅读(100) 评论(0) 推荐(0)
摘要: 1、如果小于0,修改为150, 大于100,修改为100 #include <stdio.h> void adjust(int *x) { if(*x < 0) *x = 150; //变量的值作为了下一个判断条件,如何避免? if(*x > 100) *x = 100; } int main(vo 阅读全文
posted @ 2021-05-30 15:57 小鲨鱼2018 阅读(141) 评论(0) 推荐(0)
摘要: 在c语言程序中,指针的一个重要作用就是作为函数的参数。 001:指针作为参数可以解决对传入到函数中的变量进行修改的目的。 如果要在函数中修改变量的值,就需要传入该变量的指针,然后再函数体中使用指针运算符,这样就获取了原始对象的别名,在函数体中对别名进行修改,就相当于对原始对象进行修改。 间接访问运算 阅读全文
posted @ 2021-05-30 13:30 小鲨鱼2018 阅读(1106) 评论(0) 推荐(0)
摘要: 1、c语言中函数的参数 01、c语言中实参向形参的传递过程是单向传递的,在对形参进行修改后的值不能返回给实参。 02、函数返回调用源的返回值只能有一个。 例、求两个数的和与差。 #include <stdio.h> void sum_diff(int x, int y, int sum, int d 阅读全文
posted @ 2021-05-30 12:12 小鲨鱼2018 阅读(1517) 评论(0) 推荐(0)
摘要: 1、 #include <stdio.h> void ary_set(int v[], int n, int val) { int i; for(i = 0; i < n; i++) { v[i] = val; } } int main(void) { int i; int a[5] = {1,2, 阅读全文
posted @ 2021-05-30 09:22 小鲨鱼2018 阅读(139) 评论(0) 推荐(0)
摘要: 函数间数组的传递,是以指向第一个元素的指针的形式进行的。 在被调用的函数中作为指针接收的数组, 实际上就是调用方传递的数组。 Type*型指针p指向Type型数组a的起始元素a[0]时, 指针p的行为就和数组a本身一样。 值: a[i] = *(a + i) = *(p + i) = p[i]; 指 阅读全文
posted @ 2021-05-30 08:32 小鲨鱼2018 阅读(72) 评论(0) 推荐(0)
摘要: c语言中指针运算符和下标运算符。 1、对于数组中任一元素 a[i], 一般由三个别名: *(a + i)、*(p + i)、p[i]。 其中p为指向数组第一个元素的指针(p + i 等价于 &a[i])。 对应的指针分别为: &a[i]、 a + i、p + i、&p[i]. 利用程序证明: a[i 阅读全文
posted @ 2021-05-29 22:25 小鲨鱼2018 阅读(1050) 评论(0) 推荐(0)
摘要: c语言中数组的名称原则上为数组的第一个元素的指针。(当sizeof和&应用数数组名除外)。 当p为第一个元素的指针时, p + i 为第一个元素后的第i个元素的指针,则 p + i等价于 &a[i]. 程序如下: #include <stdio.h> int main(void) { int i; 阅读全文
posted @ 2021-05-29 22:02 小鲨鱼2018 阅读(250) 评论(0) 推荐(0)
摘要: 1、 #include <stdio.h> void swap2(int *x, int *y) { int tmp; tmp = *x; *x = *y; *y = tmp; } void sort2(int *n1, int *n2, int *n3) { if(*n1 > *n2) //将前两 阅读全文
posted @ 2021-05-29 16:24 小鲨鱼2018 阅读(82) 评论(0) 推荐(0)
上一页 1 ··· 311 312 313 314 315 316 317 318 319 ··· 407 下一页