C-Language Basics review: About character

Source: Internet
Author: User

1. Overview
2. Symbols and sizes of characters
3. Character (array) Declaration, definition, initialization, reference
3.1-character declaration-definition initialization reference
3.2-character array definition initialization reference

1. Overview

Character types play a big role in C programming, especially in Linux, where everything is documented, including character devices and block devices.
Mastering all the knowledge points of the character type, able to master the C programming under Linux.
This article mainly introduces the basic data types of C language-characters, as well as the knowledge points related to characters, including:

    • Symbols and sizes of characters
    • Declaration of a character (array), definition, initialization, reference
    • Calculation of characters
    • Character (two-dimensional) array
    • String
    • Character pointer
2. Symbols and sizes of characters

In different platforms, the size of the character data type is typically represented in a 1-byte memory area because the number of characters is not large, including 26 letters and some escape characters.
1-byte 8-bit, capable of storing 256 status values, also representing a capacity of 256 characters. If the first bit of the byte is the symbol, then the state value of the -127~+127 can be stored.
In C, the definition of a character in the header file/usr/include/stdint.h, including the definition of the character type definition and the character range
The C language sample code is as follows:

#include<stdio.h>#include<stdint.h>int main(){    printf("char size is :%d\n",sizeof(char));    printf("char max is:%d  min is:%d\n",INT8_MAX,INT8_MIN);    printf("unsigned char max is:%d\n",UINT8_MAx);    retuen 0;}

The result of the execution is:

char size is : 1char max is:127,min is:-128unsigned char max is:255
3. Character (array) Declaration, definition, initialization, reference 3.1-character declaration definition initialization reference

The C language sample code is as follows:

#include<stdio.h>int main(){    //编译器分配    char char_a = ‘A‘;    printf("%c\n",char_a);    //标准输入获取    printf("输入字符:\n");    scanf("%c",&char_a);    printf("输入的字符是:%c\n",char_a);    //其他输入方式,如磁盘文件,网络套接字,进程信号等    return 0;}
3.2-character array definition initialization reference

A character array, which is an array of character types.
The string is also an array of characters, but the string includes a transfer character at the end.
The code is as follows:

#include<stdio.h># define SIZE NUMint main(){    //字符数组定义和初始化同样遵循数组的定义和初始化    //定义    char a[];    错误    char a[SIZE];    正确    //定义和初始化    char a[] = {‘‘,‘‘}    正确    char a[SIZE] = {};    正确    return 0;}

C-Language Basics review: About character

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.