strlen character array and character array the difference between sizeof and strlen Cin.get (input,arsize)

Source: Internet
Author: User
Tags first string

Strlen
What Strlen does is work on a counter that starts scanning from somewhere in memory (which can be the beginning of a string, somewhere in the middle, or even an indeterminate area of memory) until it touches the first string terminator, and then returns the counter value (length does not contain '% ').
Refers to the actual length of the actual string or array of characters (not the number of bytes in the occupied space).
Function prototypes
extern unsigned int strlen (char *s)
It means that he starts scanning from an address pointed to by the pointer, reads the characters, reads "
Strlen for character arrays or pointers

Array of character types
Char b[]={' A ', ' e ', ' s ', ' r ', ' Q '};
The bottom is not ' \ ', which means the array elements are all character types

Character array
Char c[]={"abcdef"};
The array element is also a character type, but the

Char d[]={' A ', ' C ', ' Q ', ' F ', ' w '};
I=strlen (D); In this way, because the memory allocation size of D is not specified, the length of the strlen can cause errors.

The length of an array or string
sizeof ()---The number of bytes taken
1, for an integer character type array
2, for integer or character-type pointers
STRLEN ()---The number of bytes in a character array or string
1. For character arrays
2. For character pointers
sizeof () returns the amount of memory that the variable declaration takes, not the actual length, and sizeof is not a function, just an operator, and strlen is a function.

When you use a utility template, you need to initialize the temporary parameters, such as T temp=t (0).

Cin.get (input,arsize) will read the input until it reaches the end of the line or reads ArSize-1 characters.

Automatic variables are stacks, dynamic storage or free storage is heap

strlen character array and character array the difference between sizeof and strlen Cin.get (input,arsize)

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.