Learn point C language (22): Data type

Source: Internet
Author: User
Tags include printf

1. About the first address of the array:

#include <stdio.h>
int main (void)
{
Char Cs[2][3] = {
{' A ', ' B ', ' C '},
{' D ', ' E ', ' F '}
};
Char *P1,*P2,*P3,*P4;
P1 = P2 = P3 = P4 = NULL;
/* The following four pointers are pointing to the same address * *
P1 = &cs[0][0]; * * This best understanding * *
P2 = &cs[0];
P3 = &cs;
P4 = CS; * This is the most convenient * *
printf ("%p\n%p\n%p\n%p\n", p1, P2, p3, p4); /* Display Address * *
printf ("\n%c%c%c\n", *p1, *p2, *P3, *P4); /* Display Content * *
GetChar ();
return 0;
}

2. The address of other elements of the array:

In the example, the elements of an array should be arranged in memory in this way:

[0] [0] [0][1] [0][2] [1][0] [1][1] [1][2]

The following is the way to get the third element of an array by pointer:

#include <stdio.h>

int main(void)
{
  int nums[2][3] = {
            {11,12,13},
            {21,22,23}
           };
  int *p1,*p2;
  p1 = p2 = NULL;

  p1 = &nums[0][2];

  p2 = nums;
  p2 = p2 + 2;
//  p2 = (int *)nums + 2; /* 或者用这一句替换上面两行 */

  printf("%d,%d\n",*p1,*p2);

  getchar();
  return 0;
}

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.