指针和字符串有什么区别? [英] What is the difference between Pointer and strings?

查看:54
本文介绍了指针和字符串有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

指针和数组之间有什么区别或相同?由于数组也可以用Poiter算术运算,因此可以说数组不过是指向其最合适元素的指针.

What is the difference between a pointer and array or they are same? As a array also works with poiter arithematic so it can be said that an array is nothing but pointer to its fitst element.

推荐答案

它们都有以下差异:-

int array[40];
int * arrayp;

现在,如果您尝试查看两者的大小,则指针每次都会相同,而数组则随您的数组大小而变化

Now if you will try to see the size of both then it will be different for pointer it will same everytime whereas for array it varies with your array size

sizeof(array);\\Output 80
sizeof(arrayp);\\Output 4(on 32-bit machines)

这意味着计算机将数组中所有整数的后代视为指针无法实现的.

Which means that computer treats all the offsprings of integers in an array as one which could not be possible with pointers.

第二,执行增量操作.

array++;\\Error
arrayp++;\\No error

如果数组可能是指针,则该指针的指向位置可能会发生变化,就像在第二种情况下使用arrayp一样,但事实并非如此.

If an array could have been a pointer then that pointer's pointing location could have been changes as in the second case with arrayp but it is not so.

这篇关于指针和字符串有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆