15-Dark Horse programmer------C Language Learning notes---arrays and pointers

Source: Internet
Author: User

Dark Horse programmer------<a href= "http://www.itheima.com" target= "blank" >java training, Android training, iOS training,. NET training </a>, look forward to communicating with you! -------

Four arrays and pointers

01 The array name represents the first address of the array in memory, which represents the address information, so the array name can be interpreted as a pointer, but the array name is a constant and cannot be changed.

#include <stdio.h>intMain () {Charname[]="haha"; Charname1[]="GGGG"; Charname3[2][Ten] = {"fffff","JJJJJ"}; printf ("%s\n", name3[0]); return 0;}

02 Pointers to arrays: Defining a pointer to an array is the assignment of the first address of the array to the pointer variable.

such as: int a[10];

int *p; p=&a[0];

P=&a[0] equivalent to P=a

#include <stdio.h>intMain () {Charname[]="haha"; Charname1[]="GGGG"; Charname3[2][Ten] = {"fffff","JJJJJ"}; printf ("%s\n", name3[0]); return 0;}

03 referencing an array element by pointer: P+i represents the address of a[i], * (P+i) represents the array element A[i]

04 You can change the value of a pointer variable, but the pointer constant cannot be changed. Pointer operators have the highest precedence

05 Multi-dimensional arrays and pointers:

X[i] equivalent to * (X+i)

&x[i] equivalent to X+i

/*1. How array elements are accessed int ages[5]; int *p; p = ages; 1> array name [subscript] ages[i] 2> pointer variable name [subscript] p[i] 3> * (P + i) 2. Pointer variable +1, address value exactly Add how much, depending on the type of pointer int * 4 char * 1 double * 8*/#include<stdio.h>voidChangint*array);intMain () {intAges[] = {Ten,5, -, the, $};        Chang (ages); return 0; }voidChangint*Array) {printf ("%d\n", array[2]); }

06 pointer variables pointing to multidimensional array elements:

Pointer variables that point to a one-dimensional array consisting of M elements are defined as: type name (* pointer variable name) [length]; such as: Int (*PA) [4];

07 Strings and Pointers:

When accessing characters in a string, you can define a pointer variable, point to the first character in the string, and then use the pointer's movement to access the characters in the string

15-Dark Horse programmer------C Language Learning notes---arrays and pointers

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.