简体   繁体   中英

Can someone please explain how c-strings are used in a C++ function call?

If I have a function that contains arguments char *a or char *a[], what are the operations I can perform on them within the function? How do the char pointers work differently than a regular pointer?

A pointer is a pointer, no matter what datatype it references.

When you index values from a pointer, the memory it pointer points to is treated as an array of whatever datatype the pointer represents.

A string is just an array of characters terminated by a null (zero) character.

You can use the C string library to operate on C strings ( strlen , strcpy , strcat , etc ), and you can easily construct a C++ string object by passing it a char* .

char*

is just a pointer to a character, so anything you can do to pointers you can do to character pointers. The only difference from char* and int* is the type of the pointee.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM