C expert programming note 4

Source: Internet
Author: User

Chapter 4 shocking fact: arrays and pointers are different
Many C-language books are vague about the time when arrays and pointers are the same and when they are different. The topic that should be elaborated on here is just a few things;

A declaration is equivalent to a general declaration: it describes the object created elsewhere rather than itself;

Definition is equivalent to a special declaration: it allocates memory for the object;

X = y;

In this context, the meaning of symbol x is the address represented by x, and the meaning of symbol y is the content of the address represented by y;

The array name must be left but not left;

[Cpp]
# Include <stdio. h>
Int main ()
{
Char * p = "012345 ";
Char a [19] = "01234 ";
// Float * pi = 3.14;
Printf ("% c", p [1]);
// P [1] = ch;
Printf ("% c", a [1]);
A [1] = 'a ';
Printf ("% c", a [1]);

Return 0;
};

Code verification: 1. Only a String constant can be initialized in the definition; 2. a String constant with char * is defined as read-only; 3. a String constant defined with char a [] can be modified;


From CodeBlog

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.