[1011] <<c Language Depth analysis >> testing test

Source: Internet
Author: User
Tags case statement

/**********************************  wzsts "C-Language depth analysis" 2016 ****                     ****   &NBSP;&NBSP;&NBSP;FUN1~FUN6 Representative 6 Chapter content  ****fun10~fun19 represents the function called by Fun1  ****                     ****       the world is fine because of the rules      ****  #if (1) can run, #if (0) does not run.  **** data  author   pc       ****16.1.1 &NBSP;&NBSP;WZ&NBSP;&NBSP;VM. centos6.5   ***********************************///the first chapter    before, then change the system lost files. Think, some things, lost, can change better! * * #include  <stdio.h> #include <string.h> #define  n  10    /*   Define allocation space, while extern and define declarations, macro substitution does not allocate space  */  #define &NBSP;EPSINON&NBSP;&NBSP;0.0001&NBSP;&NBSP;FUN0 ()    &nThe bsp; /*  function has no type, and the return value has type &NBSP;*/{&NBSP;INT&NBSP;FX=10;&NBSP;RETURN&NBSP;FX;} Void static fun ()/*  even if they are of different types, they cannot have duplicate names  */{/*  int fun =10       function name, variable name do not repeat    */}void fun10 () {int i=4;int *p=null;int a[10]={ 1,2,3,4,5};char b[ ]= "ABCDE"; char *c= "ABCDE";/*  char *c[10]= "ABCDE";     error*/char d[ ]={"ABCDE"};char e[]={' W ', ' z ', ' z ', ' x '};   if (b! =null)        if (null==c)   ;        else        printf (" c isn ' t NULL\n");   else   {     NULL;          /*  detail style to prevent mistaken  */    }printf ("*********************\n");  printf (" %d\n ", sizeof (&NBSP;&NBSP;P)  ) &NBSP;;&NBSP;&NBSP;&Nbsp;      /* 4 */printf ("%d\n", sizeof (&NBSP;*P)  )  ;          /* 4 */printf ("%d\n", sizeof ( int) *i )  ;/* 4 i=0,is 0 i=4,is 16*/printf ("*********************\n");  printf ("%d\n") , sizeof (&NBSP;&NBSP;A)  )  ;         /* 40 */ printf ("%d\n", sizeof (  a[10] )  )  ;    /* 4 */printf ("%d \ n ", sizeof (&NBSP;&NBSP;&AMP;A)  )  ;        /* 4 */ printf ("%d\n", sizeof (  &a[0])  )  ;     /* 4 */printf ("%d,%d\n", sizeof (&NBSP;&NBSP;B), strlen (b)  )  ;          /* 6,5*/printf ("%d,%d\n", sizeof (&NBSP;&NBSP;C), strlen (c)  )  ;          /* 4,5*/ printf ("%d,%d\n", sizeof (&NBSP;&AMP;C), strlen (e)  )  ;          /* 4,9*/printf ("%d,%d\n", sizeof (&NBSP;&NBSP;D), strlen (d)  )  ;          /* 6,5*/ printf ("*********************\n");  } Void fun11 () {int i=-20;unsigned j=10;float ftestval=0.0,ff=0; if (ftestval==0.0)   printf ("test 1 \n");  if ((Ftestval>=-epsinon) && (Ftestval<=epsinon))  printf (" Test 2 \n ");     ff=10000000.00+0.00000001; printf (" Test 2 is  better \n f=%f d=%d\n ", FF,FF);    /*  cannot be so transformed    */    i= (int) ff;   printf (  "f=%f d=%d\n", Ff,i);         /*    forced conversion    *///bool b;  c++//if (B==false )  ;  vc++&nbsP; medium True is 1VB in true is -1 //printf ("d=%d,u=%u\n", I+j,i+j);             /*d=-10,u=4294967286*///for (j=9;j>=0;j--)   {printf ("%u\n", j);}     /* dead loop   always print       *///for (j=9;j>=1;j--)      {printf ("%u\n", j);}   /*  modified to print 9 to 1      */    scanf ("%d\n", &i) ; switch (i)   {/******       right         ********/    case 1:printf ("case 1\n");     case 2:printf ("case 2\n");    /*******      error         *******/   // case a:printf ("Case  a\n ")       /*  case statement   should be less than 20 lines    */   &nbsP;//&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;SCANF ("%d\n", &i);           switch (i)            {            case 1:printf ("case 2.1\n");break;            case 2:printf ("case 2.2\n");break;            }    default:printf (" error\n");    /*   No, there is the default error program  break has magical   case  is integer and character expression   */    /*********  error  end  **********/    }} Void fun12 () {/*for (initial value cycle condition; Loop statement) for (i=0,j=1;i<10,j<3;i++,j++) while (loop condition) {} do{}   The program performs at least one while (loop condition) */ static int i=0; //for (; i<10;i++)    for (i=0;i<= 10;i++)           /*  semi-open half-closed writing  */    {       ;     }printf ("***************\n"), while (i) { i--;p rintf ("%d", I);} printf ("%c\n");      /*  need to memorize some special ASCII values 13&NBSP;CR enter  */printf ("* * * * \ n ");d o {printf ("%d\n ", I);}      /*   no other code outside the brackets  */while (i);p rintf ("%d\n", i);p rintf ("************** *\n ");/*** long cycle efficiency is high, the program does not modify the value of the loop variable * * Cycle to short, code clear, 3 layers within the * * die cycle is not necessarily dead, it is not necessarily useless; (test how much space the machine can open, run the program that terminates) */printf (" c\n ");d o{for ( i=0;i<5;i++)     {     printf ("*");      //  if (i==1)  goto wz;      if (i==2)         continue;  /*continue termination   This (this round) cycle */       if (i==4)     /*if (i=4) results are different */                   break;     /*break   termination   This layer loop */  }printf ("%2d", i);wz:                 /*goto  It is recommended to use less jumping out of this layer loop, also can not jump out function */printf ("%d", i);p rintf ("\ n"); i-=4;              /* easy to change the number is dead cycle printing */printf ("%2d", i) ;} while (i>0);p rintf ("\ n");p rintf ("%d\n", I);}  void fun13 () {// extern    int i;          // static    int i;// unsigned  int i;//    auto    int i;// const     int i ;//  long     int i;// short     int  i;//volatile   int i;struct{}su;printf ("%d", sizeof (SU));/*&nbsP VC&NBSP;IS&NBSP;1&NBSP;,VM&NBSP;IS&NBSP;0;*/TYPEDEF&NBSP;STRUCT{INT&NBSP;L;INT&NBSP;A[0];} type;//typedef struct{int l;int a[ ];} type;/* variable length structure   variable length array, flexible array, different compiler *///typedef struct{int l;int a[10];} type;  /*   different meanings of */enum en{a=0,b,c=100,d,e}en;union check{int i;char c;} un;un.i=1;printf ("%d\n", UN.C);                       /*01 0001->1000  Small End Storage      */printf ("%d\n",  c);p rintf ("%d\n",  sizeof (EN));                /*  is a pointer on a 32-bit machine for 4  *//* differences             Enumerations        Macros ————————————————————————————— ————————— | compile-time      | determine value     | Replace, indeterminate value | | Define constants    | more than once &NBSP;&Nbsp;|  Once a     | | Editor Debug   |   can    |   not      | | Define functions     |  not    |    can be      |*/ }void fun14 () {  auto  int a=0;  const int b=1;   Register  c=2;  int datagotfromfun0=fun0 ();p rintf ("%d\n", a);  //  printf ("%d\n", &a);    //test correctly then comment                   printf ("%d\n", printf ("%d ", a));      printf ("%d\n", printf ("%d \n", a));   /* 0    ** 0  2** 0** 3*/  printf ("%d\n", c);/* printf ("%d\n", &c);   test error so comment */     /*** static  modifier variables, functions, C + + in */  printf ("datagotfromfun0 is %d\n ", DataGotFromfun0); /***   variables, functions   names involved in English grammar */printf ("%d\n ", b);/*  b++;        const==readonly  */printf ("%d\n", sizeof (int)  )  ;/*  4 */printf ("%d\n", sizeof ( a )  )  ;/* 4 */printf ("%d\n",sizeof   a   )  ;/* 4 *//* printf ("%d\n",sizeof int  )  ;   *//*      return (a); brackets can go to           */ }    void  main () {//fun10 ();//fun11 ();//fun12 ();//fun13 ();//fun14 ( );}


[1011] <<c Language Depth analysis >> testing test

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.