#include "stdio.h" #include "stdlib.h" int fun(int n){ int *p; p=(int*) malloc(sizeof(int)); *p=n; return *p; } int main(){ int a; a=fun(10); printf("%d\n",a+fun(10)); } malloc 是参生的指针需要释放free(p);
--k先减减再赋值,k--先赋值再减减
#include "stdio.h" int main(){ int k=5; while(--k) printf("%d",k-=3); }
双重for循环
#include "stdio.h" int main(){ int i,j; for (i=3;i>=1;i--){ for(j=1;j<=2;j++){ printf("%d",i+j); printf("\n"); } } }
#include "stdio.h" int main(){ int k=5,n=0; do{ switch(k) { case 1:case 3:n+=1; k--; break; default:n=0; k--; case 2:case 4:n+=2; k--; break; } printf("%d",n); } while (k>0&&n<5); }
#include "stdio.h" int main(){ int x=1,y=0; if(!x) y++; else if(x==0) if(x) y+=2; else y+=3; printf("%d\n",y); }
#include "stdio.h" int main(){ int a=0,b=0; for(;a<7;a++) { if(a%2==0) continue; b+=a; continue; } printf("%d\n",b); }
#include "stdio.h" int main() { char a='5',b; a++; printf("%d,%d\n",a-'5'+255,b=a-'5'); return 0; }
#include "stdio.h" int main() { int a=7,b=0; do{ b+=a; a-=1; }while(a--); printf("%d,%d\n",b,a); return 0; }
#include "stdio.h" int main() { int x,a=1,b=1; while(1) { scanf("%d",&x); if(x>0){a*=x;break;} if(x<0){b*=x;break;} printf("%d,%d\n",a,b); } return 0; }