C Language Learning---day1 (array of strings, pointers)

Source: Internet
Author: User

The C language does not have the same string type as in Java, so in the C language, by using a character array to hold the string, in order to distinguish it from the normal character array, we need to add the trailing end of the string

An end flag: ' \ s ', so, for example, a string: "Bht", the character array that holds the string is 4 long.

Initialization of the string:

1 Chara[4]={'b','b','T',' /'};2 3 Charb[4];4b[0]='b';5b[1]='h'.......6 7 Charc[]="BHT";

If you use the 7th line of code, the length of the character array is not 3, but 4, the system will automatically add the end of the "\" This flag!

                

About the difference between puts () and gets () two functions and the printf () and scanf () functions

In Xcode, if you use the puts () and the Get () function, the compiler will prompt the two functions to be unsafe. For what? The following is a description of get and puts, the two separate expressions

Receives a string and outputs a string that can receive spaces and tab keys, while printf and scanf are not allowed . But puts and get are not as flexible as printf and scanf, which can be output one at a time .

or receive multiple strings.

The following procedures are safe:

    Char a[]="bht";     Char b[]={'i','m'};        Puts (b);

If, at the time of defining the string (b), after forgetting to knock ' s, the output of the IMBHT analysis can be explained as follows:

In-memory scenario:

Since both the puts and the gets are read to ' \ ', the subsequent array A will also be printed to the console. There's a memory allocation problem here.

C Language Learning---day1 (array of strings, pointers)

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.