Basic course of C language (ii) data types, variables, and operators (4)

Source: Internet
Author: User

2.3 Character type (char)
With different modifiers, you can define both signed and unsigned character type variables, such as:
Char A:/*A is defined as a signed character variable * *
unsigned char l; /*l is defined as unsigned character variable * *
Characters are represented in the computer in their ASCII format, with a length of 1 bytes, a signed character number range of -128~127, and unsigned character numbers to a value range of 0~255. Therefore, in the Turbo C language, character data is processed as an integer, and if a variable is defined as char, the variable is signed, that is, it is converted to a signed integer.
The characters specified in Turbo C for ASCII code values greater than 0x80 will be considered negative. For example, a character with an ASCII value of 0x8c, defined as Char, is converted to an integer 0xff8c of 16. This is because when the ASCII code value is greater than 0x80, the highest bit of the byte is 1, and the computer thinks the number is negative, and the number represented by 0x8c is actually -74 (8c for everyone, plus 1), and-74 converts to two byte integers and is represented on the computer is 0xff8c ( For 0074 members, take the counter and add 1. So only defined as
The unsigned char 0x8c is 8c when converted to an integer number. This is especially important when dealing with ASCII code word characters (such as Chinese character code) larger than 0x80. Common Chinese characters are defined as unsigned char (often encountered in future programs).
Alternatively, you can define a character array (more on the back of the array), at which point the array represents a string.
For example:
Char str[10];
At compile time, the computer will set aside 10 consecutive characters of space, that is, str[0] to str[9] A total of 10 variables, but only the first 9 for users to use. The 10th str[9] is used to hold the string terminator null that is "a", but the Terminator is automatically added by compiling the program, which should be paid special attention to.
Second, the character constant representation
Characters that can be represented by symbols can be expressed directly in single quotes, such as ' a ', ' 9 ', ' Z ' can also be represented by the ASCII value of the character, for example, the decimal number 85 indicates the uppercase ' U ', the hexadecimal number 0x5d the '] ', and the octal number 0102 denotes the capital letter ' B '.
Some control characters that cannot be represented by symbols can only be represented by ASCII code values, such as a decimal number of 10 for line breaks, and a 0x0d of the lower six to return, and an octal number of 033 to indicate ESC. There is also an alternative representation method in Turbo C2.0, such as ' \033 ' means ESC, where the number following the ' \ 0 ' symbol represents the hexadecimal ASCII value of course this notation is also applicable to characters that can be used to represent symbols.
In addition, some commonly used characters in Turbo C2.0 are represented by the following special rules:
The specified character is equivalent to meaning
' \f ' \x0c ' change page
' \ R ' \x0d ' carriage return
' \ t ' \x09 ' TAB key
' \ n ' \x0a ' wrapping line
' \ \ ' \x5c ' \ Character
' \ ' \x27 ' character
' \ ' ' \x22 ' character
For string constants, typically enclosed in double quotes, such as "Hello Turbo C2.0".
2.4 Pointer Type (*)
Pointers are a special type of data that is not generally in other languages. The pointer is the address of the variable, and essentially the pointer is the address of the storage unit. Depending on the type of variable you are referring to, can be an integer pointer (int *), floating point pointer (float *), character pointer (char *), structure pointer (struct *), and Union Pointer (union *) (Structure pointer and union pointer will be described in section 4th).

2.5 Non-value (void)
The value-free byte length is 0 and has two uses: one is to explicitly indicate that a function does not return any value; One is to produce a pointer of the same type, which can be dynamically allocated to its memory as needed.
For example:
void *buffer; /*buffer is defined as an no-value pointer.

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.