Implement strlen () function, strcmp () function const knowledge Point

Source: Internet
Author: User

1. Implementation of the strlen () function:

#include <stdio.h>int strLen (char *str); int StrLen (char *str) {int i = 0;        while (*STR) {str++;    i++; } return i;}    void Main (void) {char *str = "ABCDEFG";        int length;    Length = StrLen (str); printf ("%d\n", length);}

650) this.width=650; "Src=" Http://s4.51cto.com/wyfs02/M02/82/00/wKiom1dG5rfzdEF8AACN0aA7wsE976.png-wh_500x0-wm_3 -wmp_4-s_1712096148.png "title=" Qq20160526200608.png "alt=" Wkiom1dg5rfzdef8aacn0aa7wse976.png-wh_50 "/>

2. Implementation of the strcmp () function:

 #include <stdio.h>int strcmp (char *str1, char * STR2); int strcmp (CHAR&NBSP;*STR1,&NBSP;CHAR&NBSP;*STR2) {    while (*str1 ==  *STR2&NBSP;&&&NBSP;*STR1&NBSP;&&&NBSP;*STR2) {         str1++;        str2++;    }    &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;RETURN&NBSP;*STR1&NBSP;-&NBSP;*STR2;} Void main (void) {    char *str1 =  "Hello";     char  *str2 =  "Hell";         printf ("%d\n",  strcmp (str1 , &NBSP;STR2));} 

650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M01/82/00/wKiom1dG6EuTq_bQAACG3K97b6s046.png-wh_500x0-wm_3 -wmp_4-s_3597581615.png "title=" Qq20160526201251.png "alt=" Wkiom1dg6eutq_bqaacg3k97b6s046.png-wh_50 "/>

3, the use of const:

Const read-only.

(1) const int a = <=> int const A = 100; A space is a read-only space and the value of a space cannot be changed.

(2) const int *a;  <=> int const *A; The value of the *a cannot be changed, and the value of a pointer variable can be changed.

int* const A; The value of the *a can be changed, a pointer variable is read-only, and its value cannot be changed

const int* const A; *a, A is read-only space, and its value cannot be changed!

Const from WHO in, decorate who, who can not change!!!


Note: You just started programming with Linux (1). Linux 64-bit vs. 32-bit differences:

The int is 4 bytes. 64 bits, long 8 bytes, pointer 8 bytes

(2). Comments block under Linux: #if 0 (Note) 1 (not commented)

#endif

(3). Gcc-c only compile does not connect gcc. C-o target file compilation and connection

(4). objdump-d Test (executable file) > x86 disassembly file to view X86 content.

Compilation results often with the platform, compiler relationship is very big!!!


Implement strlen () function, strcmp () function const knowledge Point

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.