C指標編程之道 ---第四次筆記

來源:互聯網
上載者:User

標籤:style   io   ar   os   sp   for   strong   on   amp   

//多為數組的指標學習
//定義二位元組
//int date[4][5];
//說明這個數組的所有成員都是int類型
//int date[4][5] = {
// {1, 2, 3, 4, 5},
// {1, 2, 3, 4, 5},
// {1, 2, 3, 4, 5},
// {1, 2, 3, 4, 5}
//};
//或者int date[4][5] = {1,2,3,4,5,1,2,3,4,5,1,2,3,4,5,1,2,3,4,5};
//例子訪問二位元組
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
int date[4][5] = {
{1, 2, 3, 4, 5},
{1, 2, 3, 4, 5},
{1, 2, 3, 4, 5},
{1, 2, 3, 4, 5},
};
printf("date[4][5]:\n");
for(int i = 0; i < 4; ++i)
{
for(int j = 0; j < 5; ++j)
{
printf("%d ", date[i][j]);
}
printf("\n");

}
return 0;

}




//指標與二維數組
//利用指標查看每個元素在記憶體的地址是多少?
//急事把指標指向每個記憶體單元的開始
//例如 &date[i][j] 就是去每個元素的地址的意思。
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
int date[4][5] = {{1, 2, 3, 4, 5}};
printf("每個元素的地址是:");
for(int i = 0; i < 4; ++i)
{
for(int j = 0; j < 5; ++j)
{
printf("%p\t", &date[i][j]);
}
printf("\n");
}
return 0;
}



//指標的指標
//
//int * *date;
//指向指標變數的指標;
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
char *name[] = {"China", "BeiJing", "LongMai"};
char ** p_name;
printf("name[0] :%p\n", name[0]);
printf("name[1] :%p\n", name[1]);
printf("name[2] :%p\n", name[2]);
printf("\n");
p_name = &name[0];
printf("&name[0] : %p\n", p_name);


p_name = &name[1];
printf("&name[1] : %p\n", p_name);


p_name = &name[2];
printf("&name[2] : %p\n", p_name);


printf("\n");
return 0;
}

C指標編程之道 ---第四次筆記

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.