What is the difference between char s string and char s string?

Updated on technology 2024-03-12
6 answers
  1. Anonymous users2024-02-06

    chars[10]

    Refers to: a pointer that points to 10 chars of memory space.

    string

    is a class. has its own member functions and variables.

    Let me give you a few examples:

    chars[10];

    stringss;ss

    hello";In fact, the constructor of string is called to assign the initial value.

    memcpy(s,,sizeof(s));

    Calling the member function of SS returns a string pointer.

  2. Anonymous users2024-02-05

    Yes. The previous one cannot be changed.

    voidmain()

    char*pstr1

    hello!";

    charpstr2

    hello!";

    change(pstr1);

    change(pstr2);

    voidchange(char*

    pinstr)

    pinstr[0]='o';

    Both changes compiles pass, but found that the second change is correct to modify the first letter for'o', and the first one will fail to operate and cause the program to die.

    The basic knowledge is too poor, the wooden method, checked the information, and there is a difference between the two methods of defining the string.

    The string pointer variable itself is a variable that holds the first address of the string. The string itself is stored in a contiguous memory space starting with the first address, with '0' as the end of the string. An array of characters is made up of several array elements, which can be used to hold an entire string.

  3. Anonymous users2024-02-04

    1. The type is different, char is a character type, and string is a string type.

    2. The string string is used""to contain strings, char is used''to contain a single character.

    char a='1';Define a character.

    string b="dadsa";Define a string.

    3. The result stored inside the string is an array of char characters.

    private final char value;This is the structure used in string to store values.

  4. Anonymous users2024-02-03

    First, the concept is different.

    char *str declares a pointer that can point to any string constant. char str declares an array of characters, and the contents of the array can be anything, strictly speaking, by the end'\0'After that, it can be regarded as a string, and second, the variables are different.

    str in char *str is a pointer variable, and the value of str is not initialized (for local variables). The global is automatically initialized to null). In char str[ ], str is the address constant, and the value of str is the address of str[ ].

    3. Different definitions:

    In char*str, it is obvious that the type of str is char*. It's nothing special, just a simple char pointer. char str cannot be defined in this way, so it is assumed that char str[6] = abcde";So the str type here is char[6] (6, not 5, because there is a 0 at the end), and this definition statement is the only way to define a char[6] type.

  5. Anonymous users2024-02-02

    Let's start with an example:

    char str: The str in this column represents an array pointer of the char type, and the contents of the array pointed to by the pointer are stored on the stack and can be modified by knowing.

    char*str is a character beam hall character string pointer, this pointer points to the address of the first character of the string, and this pointer exists on the stack, but the content of the string is not in the stack, but stored in the character constant area.

    So look at char *str1 = abcd1234"with char *str2="abcd1234", they are both the addresses of the stored character a, so this address is the same, so the value of %p is also the same;

    But oak char str3 abcd1234"with char str4 abcd1234"There are two arrays of type char, and str3 and str4 represent array pointers of type char respectively, so their addresses are different.

    Here's how to flip a string:

  6. Anonymous users2024-02-01

    In 1 c, char* stands for the character pointer type, and when it points to the first element of a string, it can represent the string.

    2 Examples. #include

    int main()

    The result of the run is:

    learn c

    3 Analysis. in char *str="learn c";Medium,"learn c"is an array of characters of length 8 constant, the last element of which is'\0', and the result of the execution of this sentence ** is to point str to"learn c"The first character'l', and the continuous memory behind str is stored in turn'e','a','r','n','c','0'

    4 Extensions. Strings in C are represented by an array of characters, except that C prescribes a string-ending flag, i.e., characters'\0', that is, encountering a character'\0', the string ends.

Related questions
4 answers2024-03-12

divide, separate both have the meaning of "separate". divide means to divide a whole silver spike into several parts, e.g. divide the class into two groups >>>More

6 answers2024-03-12

1. The concept is different:

The rule of virtue requires the ruling group to set an example, pay attention to self-cultivation and diligence, and give full play to the role of moral influence; Attach importance to the moral education of the people, "for the government to be virtuous", and morality is the main punishment and auxiliary. >>>More

17 answers2024-03-12

The high school students confirmed the direction of Switzerland and learned a lot about the school, compared to other Chinese high school students, you still have a little plan, like one. >>>More

14 answers2024-03-12

Harmony makes money. Harmony is precious.

And and the beauty of the United States. Gentle drizzle. >>>More

8 answers2024-03-12

If you feel that the power is enough, then the power is no problem, if you feel that the power is not satisfied, you can also ECU power upgrade, HDP special official website has improvement data and**, if you are interested, you can take a look!