常量指针数组或指向数组的指针?什么是更快的C?
发布时间:2020-12-16 10:50:34 所属栏目:百科 来源:网络整理
导读:您好,我现在正在中级C课,这个想法刚出现在我脑海中: int multi[3][4]; // const multidimensional arrayint* ptr = *multi; // ptr is a pointer variable that hold the address of multi const array 那么,访问多维数组位置的更快/更小/优化是什么? 这个
您好,我现在正在中级C课,这个想法刚出现在我脑海中:
int multi[3][4]; // const multidimensional array int* ptr = *multi; // ptr is a pointer variable that hold the address of multi const array 那么,访问多维数组位置的更快/更小/优化是什么? 这个: multi[3][1]; // index the value position 要么 *(*(multi+2)+1); // pointer to the position on the array 或(更新) ptr += 9; // pointer arithmetic using auxiliary pointer 由于“multi”是一个const数组,编译器应该“知道”元素位置的本地化,如果使用指向该数组的变量指针可能需要更多的处理时间,另一方面可能在搜索时更快我想要显示的项目.什么是更快/更小/优化的方法? 先感谢您. 解决方法
它们都以相同的方式编译,*(pointer_to_first_element x y).
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |