Realized by STRUPR,STRLWR If you convert a character constant to a variable to modify it, the static storage of the constant is realized.

Source: Internet
Author: User

#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.

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.