C language pointers and structures for review of data structures

Source: Internet
Author: User

Data Structure Pointer review:
#include <stdio.h>voidMain () {inta[5] = {8,2,3,4,5}; //a[3] = = * (3+a)printf ("%d\n", *(3+a));//A[3] 4printf"*a is actually a[0]:%d\n", *a);//8//the address is continuous.printf"%p\n", A +1); printf ("%p\n", A +2); printf ("%p\n", A +3);}

A one-dimensional array name is a pointer constant that holds the address of the first element of a one-dimensional array, and its value cannot be changed.
A one-dimensional array name points to the address of the first element of the array. (get) modifies an array to pass in the length of the address and array of the first element.

#include <stdio.h>voidShow_array (int*p,intLen) {p[0] = -1; inti;  for(i =0; i < Len; i++) {P[i]= P[i] +1; printf ("%d\n", P[i]); }}intMainvoid){    inta[5] = {1,2,3,4,5}; Show_array (A,5);//A is equivalent to &a[0], &a[0] is itself an int * type    return 0;}
To modify the value of an argument through a function:
#include <stdio.h>void f (int *p) {    ;} int Main (void) {    int;        F (&i);    printf ("%d\n", i);         return 0 ;}
Structure usage Overview: Structs have only attributes and no methods. A struct is a transition of a class. Why is there a struct?    in order to represent some complex data, the common basic type does not meet the requirements. What is a struct?    A struct is a composite data type that users define themselves according to their actual needs.
#include <stdio.h>#include<string.h>structStudent//defines a new data type{    intSID; Charname[ $]; intSage; }; //semicolons cannot saveintMainvoid){    //defines a data type that is a struct student variable St    structStudent st = { +,"Zhangsan", -}; printf ("%d%s%d\n", St.sid, St.name, st.sage); St.sid= About; strcpy (St.name,"Lisi"); St.sage= A; printf ("%d%s%d\n", St.sid, St.name, st.sage); return 0;}

To be Continued ...

C language pointers and structures for review of data structures

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.