#include <stdio.h>#include<string.h>intMain () {Chars[]="copywrite 1999-2000 GGV Technologies";Char* S2=STRUPR (s);//converts a string in an S array to uppercase and returns s for initializing S2printf"%s", S2);p rintf ("%s", s);//at this time s and S2 are equal, pointing to the same string. //Note: You cannot use the following method to invoke//char* p= "for test";//STRUPR (p);//This call generates an exception because the pointer p is defined here as a constant string, and the constant string we know is not to be changedGetChar ();return 0;}
Personal understanding is as follows:
There is no specific string variable in the C language, and if you want to keep a string in a variable for saving, you must use a character array, that is, a character array to hold a string, and each element in the array holds one character.
In a program, a string constant generates a "constant pointer to a character." When a string constant occurs in an expression, the value used by the expression is the address that these characters store, not the characters themselves. Therefore, you can assign a string constant to a pointer to a character, for example: char *a = "123"; A = "abc", which points to the address stored by these characters. However, you cannot assign a string constant to a character array, because the direct value of the string constant is a pointer, not the characters themselves. For example: char a[5];a[0] = "a"; it is wrong, error result: invalid conversion from ' const char* ' to ' char '.
The pointer form simply tells the pointer the address of the constant, and the program cannot modify the address area of the constant at execution time, and the array form assigns the constant to an array variable.
Realized by STRUPR,STRLWR If you convert a character constant to a variable to modify it, the static storage of the constant is realized.