C Language Learning ---- escape characters, constants

Source: Internet
Author: User

C Language Learning ---- escape characters, constants
C language learning involves several major aspects: language, algorithm, data structure, system calling, and design. Today I want to talk about some simple knowledge escape characters for escape characters and constants. To put it bluntly, it is "/" + other characters. Here we will not describe the basic escaping here. Each document should have one. I want to talk about some mistakes. 1. Output printf ("\" "); or printf (" % c ", '"'); Output printf ("\") with a single slash ("\\"); 2. What if I output a string of paths? Like this printf ("C: \ test \ add \ 11-25 \ test. c"); what will be output? Obviously, the desired path cannot be input, and the output result should be C: estdd-25 est. c (the center is separated by a tab) to output the desired result, escape is used here. All the original single slashes are changed to double slashes, printf ("C: \ test \ add \ 11-25 \ test. c "); 3. For question 2, ask another question. Check the following program: int a; a = strlen (" C: \ test \ add \ 11-25 \ test. c "); printf (" % d ", a); what is the output result? You may wish to give it a try. After all characters are escaped, no matter what they are, they only occupy one place. For constants, common constants include scalar, integer, floating-point, and enum. You do not need to explain the first several types. For enumeration, you still want to say a few more. 1. First, let's take a simple enumeration example (all names are random): enum OS {WIN, LINUS, UNIX}; generally, we name the member in braces as a possible value, which is a constant. You can assign a value to it. If no value is assigned, the default value is 0, 1, 2 ..., if printf ("% d \ t", WIN, LINUS, UNIX) is added to the preceding program ); the output result is 0 1 2. If you only assign a value to a certain number in the middle, add 1 to the next number. You can debug the result by yourself. The process of learning C is the process of constantly coding. 2. Here, we also mention the keyword "const". The data type modified by const refers to the regular type, and the values of variables or objects of the regular type cannot be updated. Compare the following two sentences of Limit: int n = 10; // n is the variable const int n = 10; // The variable is converted to a constant and cannot be modified later. Like this: const int n = 10; n = 20; the program will report an error, but really cannot change the value of n? In C language. Pointer, an almost omnipotent tool. See the following program: const int n = 10; int * p = (int *) & n; // note that the address of n is forcibly converted to a pointer, otherwise, an error * p = 20; printf ("% d", n) is reported. In this way, the output result of the program is 20. 3. First, let's look at an array program: int main () {int n = 10; int fun [n];} It is easy to see that the program is faulty. in C language, the array width must be a constant. Can the program be correctly compiled if const is added before the third-line program? You can try it. Note: The array space has been opened up before compilation.

Related Article

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.