Summary of several confusing knowledge points in C Language

Source: Internet
Author: User

1. pointer array and array pointer

(1) int * q [10]; pointer array, which declares an array pointing to 10 integer pointer elements.

(2) int (* p) [10]; array pointer, which declares a pointer pointing to 10 integer arrays.

A pointer array is an array with elements as pointers, while an array pointer is a pointer with elements as pointers to arrays.

 

 

2. function pointers and pointer Functions

(1) int (* p) max (int a, int B); function pointer. p indicates a function that points to the parameter type of int, int, And the return value is int, you can assign this type of function to p as the first address.

(2) int * max (int a, int B); pointer function. a function that returns a pointer type is called a pointer function.

 

3. Use a String constant to initialize the pointer and array

(1) char * p = "gooseberry"; character pointer. The String constant created during pointer Initialization is defined as read-only. If you try to modify this string value through the pointer, the program will have undefined behavior.

(2) char a [] = "gooseberry"; character array, which is the opposite of a pointer. The array initialized by a String constant can be modified. For example, the following statement:

Strncpy (a, "black", 5); change the value of the array to blackberry.

 

4. Constant pointers and pointer Constants

(1) constant pointer: a pointer to a constant. The content of the pointer to an address cannot be modified.

Const int * pi = & a; or int const * pi. * pi is a constant and * p cannot be used as the left value.

(2) pointer constant: you cannot modify the pointer of an address, but you can modify the content of the address to which it points. In addition, pointer constants must be assigned values at the same time during definition, and pointer constants cannot be released.

Define "int * const pi = & a;". pi is a constant and cannot be operated as the left value. However, indirect access values can be modified, that is, * pi can be modified.


Author xuhongwei0411

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.