Character array & string initialization method

Source: Internet
Author: User

Character array

  1. Char c1[] = "ch111"; \ \ string literal initialization.!!! A null character at the end of the string literal is also copied to the character array, remembering to reserve space.
  2. Char c1[] ={' C ', ' B ', ' n ', ' m '}; \ \ List Initialization

How to initialize a String object:

  1. string S1; \ \ Empty string
  2. String S2 (S1); \\s2 is a copy of S1.
  3. String s2=s1; \ ditto
  4. String S1 ("value"); \ \ literal initialization??
  5. String s1= "value; \ \ Copy Initialization
  6. String S1 (3, ' C '); \\3 A string consisting of C

Character array & string initialization method

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.