#include<stdio.h>
#include<stdlib.h>
void yi_39(){
int *a,*b,*c;
a=b=c=(int*)malloc(sizeof(int)); // abc 指向一个整型的内存空间
*a=1;
*b=2,*c=3; // 最后赋值的,保留该空间内
a=b;
printf("%d %d %d",*a,*b,*c);
printf("hell");
}
// 兼顾从小到大和从大到小
void san_27(int b[],int n,int flag){
int i,j,t;
for(i=0; i<n-1;i++)
for(j=i+1;j<n;j++){
if(flag?b[i]>b[j]:b[i]<b[j]){
t=b[i];
b[i]=b[j];
b[j]=b[i];
}
}
}
void si_16(){
int a,c;
char b,d;
scanf("%d%c%d%c",&a,&b,&c,&d);
printf("%d,%c,%d,%c",a,b,c,d);
}
// 输入格式符的问题
void liu_30(){
char name[20];
int num;
scanf("name=%s num=%d",name,&num);
printf("%s, %d",name,num);
}
void qi_29(){
//字符串和字符数组
char *s;
s="hello";
printf("%s\n",s);
char s2[10]={'h','e','l','l','o'};//字符串赋值时,不用大括号(只有字符数组赋值才用)
char s3[10]="hhw";// 若不指明长度,则就是错误的
// char s3="lkj";// 字符数组名赋值就是错误的
printf("%s",s3);
}
// #define 相关知识
// 有意思的题目
#define N 5
#define M N+1
#define f(x) (x*M)
void ba_38(){
printf("%d\n",f(2));
printf("%d\n",f(1+1));
}
// 有意思的题目
void ba_22(){// 测试
int x=8;
for(;x>0;x--){
if(x%3){
printf("%d",x--);
continue;
}
printf("%d",--x);
}
}
// ++a,a++的区别
void test_plus_plus(){
int a=10,b=10;
printf("%d\n",a--);
printf("%d",--b);
}
void test_comma(){
// int b=2,3,4; 这样会出错
// printf("%d\n",b);
int a=2;
int b=3;
int c=(1,2,4,5);
printf("%d\n",c);
}
void test_char(){
char c1='x';
char c2='\\';
char c3='%';
char c4='\101';
char c5='\x61';
printf("%c,%c,%c,%c,%c\n",c1,c2,c3,c4,c5);
}
void testscanf_string(){
char c[3];
scanf("%s",c);
// 输入字符串,输出也是相应字符串,跟长度没有任何关系
printf("%s\n",c);
}
// 需要注意的题目
void test_pointer(){
int a[3]={1,2,3};
int *p;
p=a;
printf("%d\n",*p++); // 先算*p 再指针+1
printf("%d\n",(*p)++);// 指针所指的元素加1
printf("%d\n",*p);
}
void test_pointer_pointer(){
int a=2,*p;
p=&a;
int **q=&p; // 指针的指针
printf("%d,%d,%d\n",a,*p,*q);
}
// 有趣的题目
void f123(int *p1){
int s=3;
p1=&s;
}
// main()
/*
int a=1;
int *p=&a;
f123(p); // 此时不改变p所指的值
printf("%d\n",a);
printf("%d\n",*p);
*/
// 神奇的题目
void test_strlen(){
char s1[]={'1','2','a'};
char s2[10]={'1','2','a'};
printf("s1 length:%d\n",strlen(s1));
printf("s2 length:%d\n",strlen(s2));
}