关于数组地址的一道题

#include<iostream>
using namespace std;

int main()
{
char a[2]={7,3};
char *p0=NULL,*p1=NULL;
p0=&a[0];
p1=&a[1];
cout<<p0<<endl;
cout<<p1<<endl;
cout<<p0-p1<<endl;
cout<<"************"<<endl;
cout<<(int*)p0<<endl;
cout<<(int*)p1<<endl;
cout<<(int*)p0-(int*)p1<<endl; 

system("pause");
return 0;
}

结果:

分析:

p,p1是char型的指针,指向的是数组元素的地址,所以相差1。

时间: 2024-07-29 06:12:23

关于数组地址的一道题的相关文章

C-循环,获取数组地址的几种方法

程序的调试的作用: 跟踪CPU执行代码的步骤 监视变量的值在程序执行的时候是如何变化的 do-while 和 while 在实际的开发中, do-while比较少用 因为就算循环无论如何要至少执行一次的时候,while也可以搞定 循环的情况一共就两种: 1.循环次数确定的循环 2.循环次数不确定的循环,但是确定了循环继续活着结束的条件 对于一个一位数组来说 1.获取 a[i]的地址的几种方法 1 &a[i] // 取地址符 1 a+i // 数组名就是数组首地址 1 int *p = a; 2

C++入门经典-例6.12-使用数组地址将二维数组输出

1:以a[4][3]为例 a代表二维数组的地址,通过指针运算符可以获取数组中的元素 (1)a+n代表第n行的首地址 (2)&a[0][0]既可以看作第0行0列的首地址,同样也可以被看作是二维数组的首地址.&a[m][n]就是第m行n列元素的地址 (3)&a[0]是第0行的首地址,当然&a[n]就是第n行的首地址 (4)a[0]+(n-1)表示第0行第n个元素 (5)*(*(a+n)+m)表示第n行第m列 (6)*(a[n]+m)表示第n行第m列元素 2:代码如下: // 6

数组地址指向 注意

形参list指向同一个地址空间,下一个循环将前一个循环的值覆盖,所以加入ArrayList<Integer[]> AllPath中的数组元素相同. 解决: 每次创建一个变量,就不会被覆盖之前的值了. 原文地址:https://www.cnblogs.com/musecho/p/11597945.html

php数组练习十六道题

<?php /** * 1.写函数创建长度为10的数组.数组中的元素为递增的奇数.首项为1. */ $ary = range(1, 10); //Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 [5] => 6 [6] => 7 [7] => 8 [8] => 9 [9] => 10 ) print_r($ary); /** * 2.创建长度为10的数组,数组中的元素为递增的等比数,

关于取数组地址的识记(&amp;s+1,s+1,&amp;s[0]+1)

1 #include <stdio.h> 2 #include <malloc.h> 3 4 int main() 5 { 6 char s1[] = {'H', 'e', '1', '2', 'o'}; 7 char *p=(char *)(s1+3); 8 printf("*p:%c\n",p[0]); 9 char *p2=(char *)(&s1[0]+4); 10 printf("*p2:%c\n",p2[0]); 11 c

VBA中一个过程或函数返回多个值(数组地址)

获得macro1中的数组 Sub xx()Dim s() As Integermacro1 5, sMsgBox s(0) & vbCrLf & s(1)End Sub Sub macro1(ByVal x As Integer, ByRef sa() As Integer)ReDim sa(1) x = 1 sa(0) = x + xsa(1) = x * xEnd Sub

多维数组地址

数组地址

示例代码: #include<string.h> #include<stdio.h> int main() {     int a[2];     int b[4];     int *p1 =a;     int *p2 =b;     printf("%x\t", a-b);     printf("%x\t", a-(*p2));     printf("%x\t", (*p1) -(*p2));     retur

关于数组两个元素地址相减的问题

#include<stdio.h> int a[5]={1,2,5,9,8}; main(){ int m,n,l,q; m = a-&a[3]; n = (char*)a-(char*)&a[3]; l = (int)a - (int)&a[3]; q = (int*)a - (int*)&a[3]; //&a[3] = a + 3; printf("Test the value of a is %d\n",a); printf(&