摘要:
//功能:在s1中如果不能找到s2,则返回"Substring is not found.\n",反之.#include <stdio.h>int find_substr(char *s1, char *s2);//函数声明void main(){ if(find_substr("C is fun","un") != -1) { printf("Substring is found.\n"); } else { printf("Substring is not found.\n"); }}int find_substr(char *s1, char *s2){ int t; c 阅读全文
摘要:
//实例4 函数的引用调用#include <stdio.h>void swap(int *x, int *y);//函数申明void main(){ int i, j;//定义两个变量 i = 12;//给变量赋初值 j = 36; printf("i and j before swapping: %d %d\n", i,j); swap(&i, &j); printf("i and j after swapping: %d %d\n", i, j);}void swap(int *x, int *y)//交换函数, 参数为两个指针变量{ int temp;//定 阅读全文
摘要:
//实例3 指针操作符#include <stdio.h>void main(){ int *p;//定义一个指针变量 int begin, end;//定义两个整形变量 begin = 10;//给变量赋初值 p = &begin;//让P指向begin end = *p;//将p指向的地址中的数据赋值给end printf("begin = %d\n", begin); printf("end = %d\n", end);} 阅读全文
摘要:
//实例2 关系和逻辑运算#include <stdio.h>void main(){ int logic; int a = 1; int b = 2; int c = 3; logic = a + b > c && b <= c;//首先计算a+b是3不大于c,为假,就不会计算后面了,输出0 printf("logic = %d\n", logic); logic = a >= b + c || b == c;//b+c是5,a是小于5的,为假;输出0 printf("logic = %d\n", logic); logic = !(a < 阅读全文