C Pointer Learning Summary (refer to others ' summary experience)

Source: Internet
Author: User

Pointer Learning and Summary
One
1.int *p:p is combined with * first, stating that P is a pointer, and then the int is pointed to an int type.
2.int P[3]:p with [] The description p is an array, and then combined with an int, the elements in the array are of type int.
3.int *p[3]: p is combined with [] p is an array, followed by a *, the pointer to the array, followed by the int type, indicating that the pointer to the INT type.
4.int (*P) [3]:p with *, stating that P is a pointer, followed by a [] with the description of an array, the element that is combined with an int is an int type.
5.int **p:p with *, indicating that p a pointer to the type is int *, and the combined description *p is a pointer, and then combined with int, indicating that *p points to an int.
The 6.int p ():p is combined with (), stating that P is a function, and then int combines to indicate that the return value is of type int.
7.int (*p) (int):p and * Binding description p is a pointer, combined with (), indicating that a function is pointed to, and then combined with an int to explain that the return value is of type int.
8.int * (*p (int)) [3]: P is combined with (), stating that P is a function, with * The return value is a pointer, the type of the point is int* [3], and then a combination with [], the description points to an array, and then with the *, the description of the array is a pointer, and then combined with Description
The pointer to the array points to the element is of type int.
Two
The type of pointer, the type that the pointer points to, the value of the pointer, or the memory area to which the pointer itself occupies
Type of pointer: Removes the pointer name. The type of the int *ptr pointer is int*;
The type that the pointer points to: Remove the pointer name and the * to the left, the type of int **ptr is int*;
The value of the pointer, or the memory area pointed to by the pointer: in a 32-bit machine, the value of all types of pointers is a 32-bit integer, and the memory area pointed to by the pointer starts at the address represented by the pointer, and the length is a memory area of sizeof (the type the pointer is pointing to).

Third, the operation of the pointer
Char a[20];
int *p = (int*) A;
p++;//here p++, p points to the next int, the general 32-bit machine, which points to a[4], p plus sizeof (int)
Test code
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main () {

Char a[34] = "abcdefg1234567890";
int i;
int *p = (int *) A;
p++;
for (i=0;i<5;i++)
{
printf ("%d\n", &a[i]);
}
printf ("========%d\n", p);
}

Code 2 to understand:
int main () {

Char a[34] = "abcdefghij1234567890";
char *p = A;
Char **pp = &p;

Forced comprehension, the pointer as a variable, storing the address
printf ("%d\n", p);//1
printf ("%d\n", a);//Same as 1
printf ("%d\n", pp);//2
printf ("%d\n", &p);//Same as 2
printf ("%d\n", *pp);//with 1 pp->p->a then pp = &p, p = A; *PP = P

printf ("%c\n", **pp);
printf ("%c\n", *p);

}

Understand 3:
int a = 12; int b; int *p; int **pp;
p = &a;
*p = A;
PP = &p;
*PP = &b;
**PP = A;
Iv. Arrays and pointers
int a[10] = {1,2,3,4,5,6,7,8,9,0};
*a//* (a+0) 1
* (a+2)//3
V. The relationship between pointers and functions
int F () {
printf ("This is f.\n");
return 1;}
int main ()
{
Int (*PF) ();
PF = &AMP;F;//PF = f also possible? function f is the address directly in memory?
PF ();
}
Vi. type conversion of pointers

int a = 10;
int b;
Char *str;
int *ptr;
PTR = &a; PTR-A, PTR save-a address
printf ("%d\n", PTR);
printf ("%d\n", &a);
b = (int) ptr;
printf ("%d\n", b);
str = (char *) B;STR-B, because B is int,str is a string, so you want to cast
printf ("%d\n", str);
PTR = (int *) &c;
printf ("%d\n", PTR);
printf ("%d\n", &c);

/**************************
Other people's suggestion data structure bar, algorithm only
is eternal, programming language endless, never learn. After the study, I'll chew it carefully.
Under the STL this bone bar, recommended books--------Paradigm programming and STL and STL source code analysis.
**************************/


C Pointer Learning Summary (refer to others ' summary experience)

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.