Pointers and linked list structure understanding

Source: Internet
Author: User


Pointers and linked list structure understanding
#include <stdio.h>
int main (void)
{
int a=3,*p;
p=&a;
printf ("a=%d,*p=%d\n", a,*p);
*p=10;
printf ("a=%d,*p=%d\n", a,*p);
printf ("Enter A:");
scanf ("%d", &a);
printf ("a=%d,*p=%d\n", a,*p);
return 0;
Analytical:
1. Define shaping variables A and shaping pointer p:int a=3,*p;
2. Assign the address of variable A to the pointer P, which is p pointing to a:p=&a;
3. The value of the output variable A and the value of the pointer p point to the variable: printf ("a=%d,*p=%d\n", a,*p);
4. Assign a value to the variable that the pointer p points to, which is equivalent to assigning a value to the variable a: *p=10;
5. The value of the output variable A and the value of the pointer p point to the variable: printf ("a=%d,*p=%d\n", a,*p);
6. Enter a:printf ("Enter a:");
scanf ("%d", &a);

Pointer variables are used to store addresses, whereas general variables store values. A pointer variable occupies four bytes. The format is the type name * pointer variable name.
The fetch address operator is &. Gets the address value from it.
* is an indirect access operator.

The dynamic linked list structure does not require a continuous storage space, and the nodes of the linked list are connected by pointers. In contrast to the array structure, there is no need to move a large number of elements when the linked list is inserted or deleted, just modify the corresponding pointer. Therefore, the list structure is particularly suitable for a large number of inserted or deleted programs.
The list structure contains two items: The 1,data variable, the struct type variable, and the data part of the linked list structure.
2, the pointer part, the pointer name is *next, through which it can point to the next node. *link is also a small pointer.
In a program where you need to use a linked list, you can write a node type directly.



ITCSC 15-2 class 150809227

Pointers and linked list structure understanding

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.