A small error in the pointer in the C language

Source: Internet
Author: User

You need to assign a value to a pointer after you define the pointer before you can use *p to assign or assign a value, which is a fundamental problem, without understanding, causing a problem.

A null pointer, also called a dangling pointer, is a pointer that uses an uninitialized one.
When a pointer variable is not initialized, its value is not no, but an incorrect
Fixed value, its direction is also indeterminate, may damage the system normal
Working state, with disastrous consequences.
Cases:
M Ain ()
{int a = ten, *p A;
*p A = A:
*pa +=5;
Prin TF ("a=%d", p a);
)
The program in this example is intended to use the pointer to increase the value of the variable a
Add 5, but because the pointer pa is not initialized, it points to an in-memory
The unknown position, that is, the pointer pa itself is indeterminate. So the data
cannot be calculated correctly. Before using the pointer, point it to a
Valid address, will * PA=A; change to pa=& A;
The function that should be.

A small error in the pointer in the C language

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.