[C++] the pointer array & the array's pointer

void main(){

    // the pointer array
    char* arry[] = { "hello", "world", "haha" };

    for (int i = 0; i < 3; i++){
        printf("string:%s,address:%p\n", arry[i], arry[i]);
    }

    // the array‘s pointer
    int a[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
    printf("a[0]->%d\n",*a);// 0
    printf("a[1]->%d\n", *(a + 1));// 1
    printf("a[2]->%d\n", *(a + 2));// 2
    int(*p)[10];
    //p = a;  error: "int*" can not be assigned to "int(*)[10]"
    p = &a;
    printf("**p->%d\n", **p);// 0
    printf("(*p)[0]->%d\n", (*p)[0]);// 1

    printf("*(*p + 1)->%d\n", *(*p + 1));// 1
    printf("(*p)[1]->%d\n", (*p)[1]);// 1

    printf("*(*p + 2)->%d\n", *(*p + 2));// 2
    printf("(*p)[2]->%d\n", (*p)[2]);// 1
    //size
    printf("sizeof(p)->%d\n", sizeof(p));// 4
    printf("sizeof(*p)->%d\n", sizeof(*p));// 40

    system("pause");
}

[C++] the pointer array & the array's pointer

时间: 2024-12-15 02:55:20

[C++] the pointer array & the array's pointer的相关文章

theme(&#39;item-list&#39;,array(&#39;items&#39;=&gt;array(&#39;aaa&#39;,&#39;bbb&#39;))) 是如何运行的 ?

$items['items'] = array( l('Configure', 'admin/config'), l('Structure', 'admin/structure'), ); $theme = theme('item_list', $items); 1,  判断是否所有的模块都加载了, if (!module_load_all(NULL) && !defined('MAINTENANCE_MODE')) { throw new Exception(t('theme() may

JavaScript定义数组的三种方式(new Array(),new Array(&#39;x&#39;,&#39;y&#39;),[&#39;x&#39;,&#39;y&#39;])

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-

Linux Array & Associative Array

Ordinary Array: Assign1: arrayName=(value1 value2 ...) Assign2: arrayName[index]=value Length: ${#arrayName[*]} or ${#arrayName[@]} Indexes: ${!arrayName[*]} or ${#arrayName[@]} Example: #!/bin/bash group1=(rio amos) group2[0]=bill group2[1]=frank gr

2018-6-3_《ES7的include、ES6的Array.of(),Array.from()及扩展符》

一. ES7的include //ES7,include-查找数组是否包含某个元素 返回布尔 let a=['OB','Koro1',1,NaN]; // let b=a.includes(NaN); // true 识别NaN // let b=a.includes('Koro1',100); // false 超过数组长度 不搜索 // let b=a.includes('Koro1',-3); // true 从倒数第三个元素开始搜索 // let b=a.includes('Koro1'

LeetCode 80 Remove Duplicates from Sorted Array II [Array/auto] &lt;c++&gt;

LeetCode 80 Remove Duplicates from Sorted Array II [Array/auto] <c++> 给出排序好的一维数组,如果一个元素重复出现的次数大于两次,删除多余的复制,返回删除后数组长度,要求不另开内存空间. C++ 献上自己丑陋无比的代码.相当于自己实现一个带计数器的unique函数 class Solution { public: int removeDuplicates(std::vector<int>& nums) {

Array.of() &amp;&amp; Array()

Array.of(7) 创建一个具有单个元素 7 的数组, Array(7) 创建一个长度为7的空数组(注意:这是指一个有7个空位(empty)的数组,而不是由7个undefined组成的数组). Array.of(7); // [7] Array.of(1, 2, 3); // [1, 2, 3] Array(7); // [ , , , , , , ] Array(1, 2, 3); // [1, 2, 3] Array.of(1); // [1] Array.of(1, 2, 3); //

pointer of 2d array and address

1.int a; (&a) can be used just like a pointer, with no doubt. 2.int a; cout<<(&a)<<endl; --------- Programme Run first,output:       0028FDF0: Programme Run Second,output:    003FFED0; This means that RAM allocates different storage ad

81. Search in Rotated Sorted Array II (Array; Divide-and-Conquer)

Follow up for "Search in Rotated Sorted Array":What if duplicates are allowed? Would this affect the run-time complexity? How and why? Write a function to determine if a given target is in the array. 思路:此时可能存在nums[start]=nums[end]或者nums[start]=n

154. Find Minimum in Rotated Sorted Array II (Array; Divide-and-Conquer)

Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2). Find the minimum element. The array may contain duplicates. 思路:有重复元素的时候,不能按I中这么分三类(反例:Input: [3,3,1,3]=>将