Procedural APE's---C language detail (C language Boolean type, continue details, sizeof example, strlen example)

Source: Internet
Author: User

Main contents: Boolean type, continue detail, sizeof example, strlen example in C language
One, Boolean type

Maybe a lot of people don't know that now C has a Boolean type: Starting with the C99 standard, the type name is "_bool"

Before the C99 standard we used to imitate the definition of Boolean type, common in the following ways:

1, the way one

#define TURE 1#define FALSE 0

2, Mode two

typedef enum {false, true} bool;

3, Mode three

typedef int BOOL

idle int wastes memory and is used by memory-sensitive programs

typedef char BOOL

The bool type is introduced in the new header file in the C99 standard and is compatible with bool in C + +. The header file is Stdbool.h, and its source code is as follows:

#ifndef _stdbool_h #define _STDBOOL_H  #ifndef __cplusplus  #define BOOL    _bool #define TRUE    1 #define False   0  #else/* __cplusplus */  * supporting <stdbool.h> in C + + is a GCC extension.  */#define _BOOL   BOOL #define BOOL    BOOL #define FALSE   False #define TRUE    true #endif/  * __ Cplusplus */* Signal and all the  definitions is present.  
Second, continue

Continue details are to be used in the loop, or it will be an error

#include <stdio.h>int main () {int a = 1;switch (a) {case 1:printf ("1\n"); continue;//continue must be used to break in the loop  ; Case 2:printf ("2\n");d Efault:break;} return 0;}
Iii. Examples of sizeof

#include <stdio.h> int b[100];void fun (int. b[100]) {printf ("in fun sizeof (b) =%d\n", sizeof (b));//sensory function The array is handled by the pointer}in T Main () {char *p = null;printf ("sizeof (P) =%d\n", sizeof (p));p rintf ("sizeof (*p) =%d\n", sizeof (*P));p rintf ("---------- -------------\ n "), char a[100];p rintf (" sizeof (a) =%d\n ", sizeof (a));p rintf (" sizeof (a[100]) =%d\n ", sizeof (a[100])); printf ("sizeof (&a) =%d\n", sizeof (&a));p rintf ("sizeof (&a[0]) =%d\n", sizeof (&a[0]));p rintf ("------ -----------------\ n "); fun (b); return 0;}
Output:

Iv. Examples of strlen

#include <stdio.h> #include <stdlib.h> #include <string.h> #include <stdbool.h>/* questions 1, 0 and + 0 How to store 2, int i = -20 in memory respectively;   unsigned j = ten;   What is the value of i+j? Why? 3. What's wrong with the following code? unsigned i;for (i = 9; i>=0; i--) {printf ("%u\n", I);} */int Main () {bool bool2 = 0;  /* C language Bool type is only in C99, if not include header file stdbool.h, directly with Bool will report error */_bool bool1 = 1; /* Direct use of _bool does not include Stdbool.h*/char a[280];char *str = "12340987\0"; char test[] = "12340987"; int i;printf ("strlen (a) =%d \ n ", strlen (a)); for (i = 0; i < 280; i++) {a[i] = -1-i;//a[256]  = 0//printf (" a[%d] =%d\n ", I,a[i]);} printf ("strlen (a) =%d\n", strlen (a));  Why is 255 printf ("strlen (str) =%d\n", strlen (str));p rintf ("strlen (test) =%d\n", strlen (test)); char s = ' rintf ';p "\ \ 0 =%d\n ", s); return 0;}
Output:


Procedural APE's---C language detail (C language Boolean type, continue details, sizeof example, strlen example)

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.