For learning iOS, attack ... C Language Pointer Practice

Source: Internet
Author: User

Using pointers, give you array int a[] = {4,34,32,13,15,66};(A + 1), Output *a + 1,* (ptr1-1), *PTR2), and give the solution process.


#include <stdio.h>

int main (int argc, char const *argv[])

{

int a[] = {4,34,32,13,15,66};

int *PTR1 = (int *) (&a + 1);

/*

(&a+1) represents the address of the next block of memory for the storage array a[] memory address, * (&A+1) represents the value of the address after the a[] array, and PTR1 represents the address of this value.

The back output (PTR1-1) is returned to the memory address of the array a[] itself, and is the last small memory address inside, * (PTR1-1) is to take out this value

*/

int *PTR2 = (int *) &a + 1;

printf ("%d%d%d%d\n", * (A + 1), *a + 1,* (ptr1-1), *PTR2);

/*

(a+1) is the address of a[0] stored inside the array a[], to the address of the a[1], still in a[] this large space, quite an array of subscripts from 0+1. * (a+1) is the value in the corresponding address

*a + 1 is to first take out the value stored in address A, then this value +1,

*/

return 0;

/ * Result of this function output:

Imacdeimac-18:desktop imac$ cc zhizhenzuoye.c

Imacdeimac-18:desktop imac$./a.out

34 5 66 34

*/

}


For learning iOS, attack ... C Language Pointer Practice

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.