Embedded C-language pointer with the Tang notes

Source: Internet
Author: User
Tags naming convention null null

A pointer is also a variable that is used to store an address.

Variables can be manipulated indirectly,

The null NULL address and 0 are equivalent

Can point to any address during program execution

The naming convention for pointer variables is the same as the naming conventions for other variables
Pointer cannot have the same name as an existing variable
The pointer holds the address of any basic data type, array, and all other high-level structures in the C language
If the pointer is declared as an address pointing to a type of data, it cannot be used to store addresses of other types of data
You should specify an address for the pointer before you can use the pointer in the statement
A pointer is a variable that can change its value during the execution of a program, which can change the pointer's direction. You can point to the variable x at some point, or you can point to the variable y at another time

The harm of the pointer uninitialized;

Initialization refers to the definition and assignment of a value

#include <stdio.h>
int main ()
{
int *pa;//Wild pointer
printf ("pa=%p\n", PA);
printf ("*pa=%d\n", *PA);
Segment error: illegal memory was manipulated

*pa+=10;

return 0;
}

A pointer variable occupies a memory address that is 4 bytes

The operation of pointers;

1. Pointers and pointers

#include <stdio.h>
int main ()
{
int a=12;
int b=34;
int *pa=&a;
int *pb=&b;
int C=PA+PB;
return 0;
}
~ 650) this.width=650; "Src=" "/>

Two addresses add no meaning error

converting int C=PA+PB to int C=PA-PB will not give an error. Because int C=PA-PB is a distance representing 2 addresses, it is meaningful.

2. The addition and subtraction of pointers and integers is the offset of the address

Offset =n*sizeof (type)

&arr : The first address of the entire array   offset 5*sizeof (int)                                                                                                

&arr+1 VS & (arr+1)

& (arr+1) is not valid, cannot take address of address

Equivalence between pointers and arrays

If the int *p=arr

PA equivalent to &arr[i]

*PA equivalent to arr[0]

int *PA store int or int[]


Embedded C-language pointers with notes

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.