青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

chenglong7997

知識點:

1。多維數(shù)組的單個元素的存儲和引用實際上是以線性 形式排列在內(nèi)存中的。

2.使用指針向一個函數(shù)傳遞一個多維數(shù)組。
myfunction(int my_array[][20]);

myfunction(char **my_array);
參數(shù)必須是指針數(shù)組,而且必須是指向字符串的指針數(shù)組。

char_array[rowsize *i +j]=....
將二位數(shù)組轉(zhuǎn)換成以為數(shù)組  
posted @ 2012-06-23 05:02 Snape 閱讀(180) | 評論 (0)編輯 收藏
知識點:

1.數(shù)組和指針。
 1 #include <stdio.h>
 2 #include <stdlib.h>
 3 
 4 void test(int arr[])
 5 {
 6     printf("In Func: size of the array is %d\n", sizeof(arr) );    //4 the pointer's size
 7 }
 8 
 9 void test_char(char arr[])
10 {
11     printf("In Func: sizeof the my_char is %d\n", sizeof(arr));    //4 the pointer's size
12     printf("In Func: strlen the my_char is %d\n", strlen(arr));    //11 the string's size
13 }
14 
15 int main()
16 {
17     int array[100]={1,3,4,5};
18     char my_char[50]="hello world";
19 
20     printf("In Main: sizeof the array is %d\n", sizeof( array) );    //400
21 
22     printf("In Main: sizeof the my_char is %d\n", sizeof(my_char));    //50
23     printf("In Main: strlen the my_char is %d\n", strlen(my_char));    //11 the string's size
24 
25     test(array);
26     test_char(my_char);
27 }
C語言允許把形參聲明為數(shù)組,或者指針。編譯器知道何時形參是作為數(shù)組聲明的,但事實上在函數(shù)的內(nèi)部,編譯器始終把它當(dāng)做指向數(shù)組第一個元素的指針。
(也因為如此,這個指針的地址,與數(shù)組第一個元素的地址不相同。)
因此,但test和test_char函數(shù)中,sizeof(pointer)的大小都是4,為指針的大小。
也因此,只能傳給函數(shù),數(shù)組的大小,因為無法用sizeof推出數(shù)組的大小。

2.有一種操作只能在指針里進行,而無法在數(shù)組中進行,就是修改它的值。
數(shù)組名是不可修改的左值,他的值是不能改變的。也可看做常量指針。

3.數(shù)組和指針的可交換性總結(jié)
用a[i]這樣的形式對數(shù)組進行訪問,總是被編譯器“改寫”成*(a+i)這樣的指針訪問
指針始終就是指針。它絕不可以改寫成數(shù)組。你可以用下標(biāo)形式訪問指針,一般都是指針作為函數(shù)參數(shù)時候,而且你知道實際傳遞給函數(shù)的就是一個數(shù)組
在特定上下文中,也就是作為函數(shù)的參數(shù),一個數(shù)組的聲明,可依看做是一個指針。作為函數(shù)參數(shù)的數(shù)組,始終會被編譯器改成指向數(shù)組的第一個元素的指針。
當(dāng)把一個數(shù)組定義為函數(shù)的參數(shù)時候,可以選擇定義為數(shù)組,也可以定義為指針,不管用哪種方法,在函數(shù)內(nèi)部事實上獲得的就是一個指針
在其他所有情況,定義和聲明必須相匹配。如果定義了一個數(shù)組,在其他文件中對它進行聲明時候,也必須把他聲明為數(shù)組。指針也是一樣。

4.數(shù)組名與數(shù)組一個元素, 與作為參數(shù)時,被編譯器轉(zhuǎn)換為的指針的關(guān)系。
#include <stdio.h>
#include <stdlib.h>


void test_char(char arr[])
{
    printf("In test_char().\n");
    printf("addr of array param = %#x \n", &arr);
    printf("content of array param = %#x \n", arr);
    printf("addr of (arr[0]) = %#x \n", &arr[0]);
    printf("addr of (arr[1]) = %#x \n", &arr[1]);
    printf("++arr = %#x \n", ++arr);
}

int main()
{
    //int array[100]={1,3,4,5};
    char my_char[50]="hello world";


    printf("addr of array head %x\n", &my_char);
    printf("addr of my_char[0] %x\n", &(my_char[0]));
    printf("addr of my_char[1] %x\n", &(my_char[1]));
    //test(array);
    test_char(my_char);
}


結(jié)果:
addr of array head bf8c0dfa
addr of my_char[0] bf8c0dfa
addr of my_char[1] bf8c0dfb
In test_char().
addr of array param = 0xbf8c0de0 
content of array param = 0xbf8c0dfa 
addr of (arr[0]) = 0xbf8c0dfa 
addr of (arr[1]) = 0xbf8c0dfb 
++arr = 0xbf8c0dfb 

結(jié)果說明:
數(shù)組名的地址與數(shù)組第一個元素的地址是相同的。因此數(shù)組名不是第一個元素的指針,而是第一個元素,除了它不能直接取出第一個元素。
在test_char 函數(shù)中。參數(shù)的地址與數(shù)組第一個元素的地址不同,而參數(shù)的內(nèi)容是第一個元素的地址。說明編譯器確實用指針實現(xiàn)了數(shù)組的訪問。指針++后,指向數(shù)組下一個元素。





posted @ 2012-06-23 02:59 Snape 閱讀(170) | 評論 (0)編輯 收藏
1.指針與數(shù)組并不相同。
定義會分配內(nèi)存。聲明不會。
聲明與定義應(yīng)該相配。
posted @ 2012-06-21 06:07 Snape 閱讀(176) | 評論 (0)編輯 收藏
知識點:

1.int 變量跟只包含一個int 成員的結(jié)構(gòu)變量,在傳遞參數(shù)的方式可能完全不同。一個 int參數(shù)一般會傳遞到寄存器中,而結(jié)構(gòu)參數(shù)很可能被傳遞到堆棧中。

2.在結(jié)構(gòu)中放置數(shù)組,可以講數(shù)組當(dāng)做第一等級類型,用賦值語句拷貝整個數(shù)組。
struct s_tag {int a[100];};
struct s_tag orange, lime;

int main()
{
    int i;
    for(i=0; i<100; i++) lime.a[i]=1;
    orange=lime; //對整個結(jié)構(gòu)賦值
}

3.union
為了節(jié)省空間
為了把一個數(shù)據(jù)解釋為兩種不同的東西。

4.enum
#define定義的名字一般在編譯時期被丟棄,而枚舉名字則通常一直在調(diào)試器中可見。可以再調(diào)試代碼的時候看見他們。

5.typedef int x[10] 與 #define x int[10]區(qū)別
可以用其他類型說明符對宏類型名進行擴展,但是不能對type的飯定義的類型名,進行擴展
#define peach int
unsigned peach i;//right

typedef int banana;
unsigned banana i;//error

在連續(xù)幾個變量聲明中,用typedef定義的類型能夠保證聲明中所有變量均為同一種類型,但是#define定義的類型不能保證。

#define int_ptr int*;
int_ptr chalk, cheese;
結(jié)果:int * chalk, cheese;(他們兩個類型不同)

#typedef char* char_ptr
char_ptr ben, rool(兩個都是指向char的指針)


6. 不要為了方便對結(jié)構(gòu)使用typedef,雖然可以省去struct但是省去了提示信息。
用在數(shù)組,結(jié)構(gòu),指針,以及函數(shù)的組合類型。結(jié)構(gòu)標(biāo)簽可以添加“_tag”結(jié)尾。
posted @ 2012-06-21 05:39 Snape 閱讀(325) | 評論 (0)編輯 收藏
知識點:

1.malloc(strlen(str)) 幾乎肯定是錯誤的。應(yīng)該是 malloc(strlen(str)+1)。

2.NUL用于結(jié)束一個ACSII字符串。NULL表示什么也不指向。空指針。

3.switch中default寫成defau1t的錯誤。(能夠通過編譯)。
break會跳出最近的那層循環(huán),或者switch語句

4.ANSI C 相鄰的字符串常量會被自動合并成一個字符串的約定。
printf("a second favorite children's book"
"is 'yitiantulong' "
);
編譯時候會自動合并,除了最后字符串外,每個字符串結(jié)尾的‘\0’會被刪除。
bug:
char *resourse[]={
"big disk",
"color"   //color 之后沒有寫逗號,那么會和mouse連接在一起。
"mouse",
};

5.代碼第一次執(zhí)行時候行為,與以后執(zhí)行的不同。
initializer( char *str)
{
    static char separator='';
    printf(" %c %s \n", separator, str);
    separator=',';
}
非常簡便,比起其他的方法。

6.extern用于函數(shù)定義,表示全局可見。(屬于冗余)
extern用于標(biāo)量,表示在其他地方定義。

7.x=f() * g();
f() 與個g() 調(diào)動順序不確定。

8.空格
\newline 與 \ newline意義不同。

9.調(diào)用函數(shù)分配內(nèi)存來保存函數(shù)的返回值。可以返回字符串常量的指針,靜態(tài)數(shù)組的指針,動態(tài)內(nèi)存指針。
posted @ 2012-06-21 04:26 Snape 閱讀(368) | 評論 (0)編輯 收藏
知識點:

1.float不會被自動擴展為double。 在ANSI C中

2.宏所接受參數(shù)類型可以不同。 最好只用于命名常量和為結(jié)構(gòu)提供簡潔記法。

3.操作符左右最好用空格分開。防止古老版本的程序,會修改賦值符的位置。

4.在limits.h中有INT_MAX, LONG_MAX定義

5.類型不兼容。因為兩個指針?biāo)笇ο蟛煌6皇切揎椃煌?br />
foo (const char **p) {}
 
int main(int argc, char **argv)
{
     foo(argv);
}

6.K&R C 和 ANSI C對待無符號數(shù)原則不同
K&R C 使用無符號保留的原則。
ANSI C 使用值保留的原則。(整數(shù)如果轉(zhuǎn)換為signed不會丟失信息,就轉(zhuǎn)換為signed,否則轉(zhuǎn)換為unsigned)
經(jīng)過gcc中測試,采用的是ANSI C的原則

7.盡量不要在代碼中使用無符號數(shù),以避免增加不必要的復(fù)雜性。不要僅僅因為無符號數(shù)不存在負值(如年齡),就用它來表示數(shù)量。
只有在使用位段和二進制掩碼時候,才可以用無符號數(shù)。在表達式中使用強制轉(zhuǎn)換,是操作數(shù)均為有符號或者無符號數(shù),這樣就不必由編譯器選擇結(jié)果的類型。


posted @ 2012-06-21 04:03 Snape 閱讀(225) | 評論 (0)編輯 收藏
知識點:

1.if(3==i)
最好用這種方式,避免少寫一個=

2.time_t在/user/include/time.h中,用一個long來表示。因此最大值為0x7FFFFFFF(有符號數(shù));
或者用biggest=(long)(pow (2, sizeof(long)*8)-1 );來獲取最大值。
之后用gmtime, asctime函數(shù)獲取最大時間

結(jié)果:
Tue Jan 19 03:14:07 2038
posted @ 2012-06-21 03:39 Snape 閱讀(194) | 評論 (0)編輯 收藏
方法1:
 1 #include <iostream>
 2 using namespace std;
 3 
 4 //by snape 2012-3-25
 5 //method 1: drawback is we need calculate the one-dimensional index to access the 2D array
 6 int main()
 7 {
 8     int rowSize, colSize, totalSize;
 9     int index, i,j;
10 
11     cout<<"Enter the row and column size for your 2D array!"<<endl;
12     cin>>rowSize>>colSize;
13 
14     totalSize=rowSize*colSize;
15     int *pArray;
16     pArray=new int[totalSize];
17 
18     //file  the array with integers from 0 to totalsize
19     //file across the rows, moving down the colums
20 
21     int arrayValue=0;
22     for(i=0; i<rowSize; ++i)    //outer-loop traverse down the "rows"
23     {
24         for(j=0; j<colSize; ++j)
25         {
26             //caculate array index
27             //index=rowSize*j+i;        //both index=rowSize*j+i; and index=colSize*i+j; are ok
28             index=colSize*i+j;            //but if index=rowsize*i+j; or index=colSize*j+i; then there will be a bug.
29             pArray[index]=arrayValue;    // i like index=colSize*i+j; since the arrange of 2D is according to rows
30             cout<<"index="<<index<<endl;
31             cout<<"i(row)="<<i<<"j(col)="<<j<<"array value"<<pArray[index]<<endl;
32             ++arrayValue;
33         }
34     }
35 
36     //output the array
37     for(int k=0; k<totalSize; ++k)
38     {
39         cout<<pArray[k]<<endl;
40     }
41     cout<<"The End"<<endl;
42     delete [] pArray;
43     return 0;
44 }
45 
46 

方法2:
 1 //by snape
 2 //method 2: better than method 1, but call new twice
 3 int main()
 4 {
 5     int rowSize, colSize, totalSize;
 6     int i, j;
 7     cout<<"Enter the row and column size for your 2D array"<<endl;
 8     cin>>rowSize>>colSize;
 9 
10     totalSize=rowSize*colSize;
11 
12     int *pArray; //pointer to an integer
13     int **pPointerArray; //pointer to an integer pointer
14 
15     pArray=new int[totalSize];    //memory for totalSize integers
16     pPointerArray=new int*[rowSize];    //memory for rowSize # of int pointers
17 
18     //fill the pointer array with the pArray[i][0] address
19     for(i=0; i<rowSize; ++i)
20         pPointerArray[i]=pArray+i*colSize;    //place the address into the pointer
21 
22     //now fill the pArray by using the pPointerArray to access elements
23     int arrayValue=0;
24     for(i=0; i<rowSize; ++i)
25     {
26         for(j=0; j<colSize; ++j)
27         {
28             pPointerArray[i][j]=arrayValue;    //cool
29             cout<<"i(row)="<<i<<"j(col)="<<j<<"array value="<<pPointerArray[i][j]<<endl;
30             ++arrayValue;
31         }
32     }
33 
34         //output the array
35     for(int k=0; k<totalSize; ++k)
36     {
37         cout<<pArray[k]<<endl;
38     }
39     cout<<"The End!"<<endl;
40     delete [] pArray;
41     delete [] pPointerArray;
42     return 0;
43 }

方法3:
 1 // by snape
 2 //method 3: better than method 2. just malloc once and the memory is contiguous block. the best
 3 int **my2DAlloc(int rowSize, int colSize)
 4 {
 5     int i;
 6     int header=rowSize * sizeof(int *);
 7     int data=rowSize * colSize * sizeof(int);
 8     int **rowptr=(int **)malloc(header+data);    //malloc memory for both data and pointerArray(the header)
 9 
10     if(rowptr==NULL)
11         return NULL;
12     int *buf=(int *)(rowptr+rowSize);    //buf: the pointer to the first data
13     for(i=0; i<rowSize; ++i)    //assign the address of each row to pointerArray(the header)
14         rowptr[i]=buf+i*colSize;
15 
16     return rowptr;
17 }
18 
19 int main()
20 {
21     cout<<"Enter the row and column size for your 2D array"<<endl;
22     int rowSize, colSize;
23     cin>>rowSize>>colSize;
24     int **p=my2DAlloc(rowSize, colSize);
25 
26     //assign values
27     int i, j, arrayValue=0;
28     for(i=0; i<rowSize; ++i)
29         for(j=0; j<colSize; ++j)
30             p[i][j]=arrayValue++;
31     
32     //output values
33     for(i=0; i<rowSize; ++i)
34         for(j=0; j<colSize; ++j)
35             cout<<p[i][j]<<endl;
36 
37     free((void *)p);
38 }

方法3,我感覺最好,只調(diào)用一次malloc, 空間連續(xù),釋放內(nèi)存也比較方便。

大家有什么想法的歡迎交流
posted @ 2012-03-27 01:20 Snape 閱讀(1669) | 評論 (6)編輯 收藏

MSVC 下面有:

1 
2 void * _aligned_malloc(
3     size_t size, 
4     size_t alignment
5 );
Unix/Linux下面有:
1 int posix_memalign(void **memptr, size_t alignment, size_t size);

自己實現(xiàn):
 1 #include <iostream>
 2 #include <stdlib.h>
 3 using namespace std;
 4 
 5 //by snape 2012-3-25
 6 
 7 void *aligned_malloc(size_t required_bytes, size_t alignment)
 8 {
 9     void *p1;    //orignal block
10     void **p2;    //aligned block
11 
12     int offset=alignment-1+sizeof(void*);
13     if( (p1=(void*)malloc(required_bytes+offset))==NULL )
14         return NULL;
15     //cast void* to void** to let p1 store into heap in the form of pointer
16     p2=(void**)( ((size_t)(p1)+offset) & ~(alignment-1) );    //add offset to p1 and then back to the aligned address
17     p2[-1]=p1;
18     return p2;
19 }
20 
21 void aigned_free(void *p2)
22 {
23     void* p1=((void**)p2)[-1];    //get the p1
24     free(p1);
25 }
26 
27 
28 
29 int main()
30 {
31     int size=10, align=16;
32     int *p=(int *)aligned_malloc(size, align);
33     
34     cout<<"The start address="<<p<<endl;
35     
36     aigned_free(p);
37 }

上面實現(xiàn)很考驗對指針的掌握。原理不是很難。

Line12:分配內(nèi)存的時候,加上alignment-1個空間,就能保證能夠找到和alignment對齊的開始地址。多出來的sizeof(void*)是為了保存malloc最初返回的指針p1而分配的一個空間

Line 17: 保存原始的malloc返回的地址p1到對齊地址的前一個空間
posted @ 2012-03-27 01:19 Snape 閱讀(1914) | 評論 (0)編輯 收藏
僅列出標(biāo)題
共2頁: 1 2 

導(dǎo)航

<2025年9月>
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

統(tǒng)計

常用鏈接

留言簿

隨筆分類

隨筆檔案

文章分類

文章檔案

my

搜索

最新評論

閱讀排行榜

評論排行榜

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            在线播放豆国产99亚洲| 国产精品劲爆视频| 伊人成人在线| 欧美成人精品一区| 免费在线成人| 一区二区免费在线视频| 亚洲日韩欧美视频| 欧美视频在线一区| 欧美伊人精品成人久久综合97| 亚洲一区二区三区免费观看| 国产区二精品视| 免费视频一区| 欧美激情在线| 性久久久久久久久久久久| 久久av一区二区| 亚洲精品久久| 亚洲尤物影院| 亚洲人人精品| 亚洲欧美资源在线| 亚洲国产欧美一区| 亚洲夜晚福利在线观看| 一区二区三区在线免费观看| 亚洲韩国一区二区三区| 国产精品久久国产精品99gif| 欧美一区影院| 欧美日本久久| 另类激情亚洲| 国产精品久久久久一区二区三区共 | 久久一区二区三区四区| 亚洲激情专区| 欧美一区二区三区视频免费播放| 1204国产成人精品视频| 亚洲特级片在线| 亚洲国产成人高清精品| 在线性视频日韩欧美| 一色屋精品视频在线看| avtt综合网| 最新国产成人av网站网址麻豆| 在线综合亚洲欧美在线视频| 亚洲电影网站| 欧美一区二区三区男人的天堂| 亚洲另类春色国产| 欧美一区二区黄色| 亚洲欧美日韩视频一区| 欧美凹凸一区二区三区视频| 久久国内精品视频| 欧美特黄一级| 亚洲日本在线视频观看| 亚洲成人在线网| 久久国产欧美日韩精品| 欧美一级久久久| 欧美日韩系列| 亚洲久色影视| 999在线观看精品免费不卡网站| 久久av老司机精品网站导航| 亚洲综合色网站| 欧美日韩在线不卡| 亚洲免费观看高清完整版在线观看| 在线观看一区| 久久女同精品一区二区| 久热精品在线| 精品盗摄一区二区三区| 久久精品人人做人人综合| 久久gogo国模裸体人体| 国产精品一卡| 午夜精品视频一区| 久久久www成人免费毛片麻豆| 国产精品九色蝌蚪自拍| 亚洲丝袜av一区| 亚洲欧美综合| 国产亚洲精品一区二555| 亚洲女同同性videoxma| 欧美伊人影院| 国内揄拍国内精品久久| 久久精品国语| 亚洲电影自拍| 宅男在线国产精品| 国产精品午夜春色av| 亚洲免费视频网站| 久久中文精品| 亚洲精品国产精品国自产观看| 欧美不卡激情三级在线观看| 91久久精品久久国产性色也91| 亚洲麻豆国产自偷在线| 欧美色道久久88综合亚洲精品| 99xxxx成人网| 久久国产婷婷国产香蕉| 激情丁香综合| 欧美区在线播放| 亚洲综合社区| 亚洲成人在线网站| 亚洲在线一区| 激情综合网址| 欧美日韩国产色综合一二三四 | 久久精品中文字幕一区| 亚洲电影免费观看高清完整版在线观看 | 亚洲国产毛片完整版| 一本色道久久综合狠狠躁篇的优点 | 欧美日韩国产综合一区二区| 日韩一级在线| 久久久美女艺术照精彩视频福利播放 | 欧美国产日韩一区二区| 一区二区三区高清视频在线观看 | 影音先锋亚洲精品| 欧美另类专区| 欧美一区二区三区男人的天堂 | 亚洲精品日产精品乱码不卡| 欧美亚洲综合久久| 亚洲欧洲精品一区二区| 国产精品夜夜夜| 蜜桃av一区| 校园春色国产精品| 亚洲毛片av| 欧美电影美腿模特1979在线看| 国产精品99久久不卡二区| 狠狠做深爱婷婷久久综合一区| 欧美日本乱大交xxxxx| 久久久久久久97| 亚洲一区二区免费看| 亚洲激情欧美激情| 女主播福利一区| 欧美一区二区视频在线观看2020| 亚洲人成在线观看网站高清| 国产日韩一区二区| 欧美小视频在线| 欧美日韩大片一区二区三区| 久久国产主播精品| 性欧美xxxx大乳国产app| 亚洲精品一区二区在线| 欧美电影在线观看| 久久伊人亚洲| 久久精品亚洲精品国产欧美kt∨| 在线性视频日韩欧美| 亚洲乱码国产乱码精品精98午夜| 黄色成人在线观看| 国产综合精品一区| 国产一区二区三区久久| 国产精品天天看| 国产精品看片你懂得| 欧美日韩亚洲一区在线观看| 欧美激情亚洲另类| 欧美电影在线免费观看网站| 老司机久久99久久精品播放免费| 久久精品国产久精国产一老狼 | 亚洲精品美女| 亚洲国产日日夜夜| 欧美黄色视屏| 91久久精品一区二区三区| 亚洲国产成人一区| 亚洲日韩成人| 99国产精品久久久久老师 | 久热精品视频在线观看| 久久综合久久综合九色| 久久在线精品| 欧美国产一区视频在线观看| 欧美激情第4页| 亚洲欧洲另类国产综合| 日韩视频在线播放| 亚洲视频第一页| 午夜影视日本亚洲欧洲精品| 香蕉乱码成人久久天堂爱免费| 欧美在线视频在线播放完整版免费观看| 亚洲先锋成人| 香港久久久电影| 鲁大师影院一区二区三区| 欧美成人一区二区三区片免费| 欧美精品久久久久久久久老牛影院| 欧美久久久久久久久| 国产精品国产一区二区| 国产综合精品| 亚洲精品一区久久久久久| 亚洲摸下面视频| 久久亚洲一区二区| 亚洲欧洲综合另类| 亚洲欧美bt| 欧美激情精品久久久久久蜜臀| 欧美性jizz18性欧美| 很黄很黄激情成人| 一区二区三区黄色| 久久精品国产第一区二区三区最新章节 | 国产精品系列在线播放| 激情懂色av一区av二区av| 一本大道久久精品懂色aⅴ| 性欧美超级视频| 亚洲国产精品va| 亚洲欧美视频在线观看| 麻豆91精品91久久久的内涵| 欧美视频日韩| 亚洲黑丝一区二区| 欧美一区二区三区的| 欧美国产亚洲另类动漫| 亚洲男同1069视频| 欧美日韩国产色视频| 在线激情影院一区| 午夜精品视频在线观看| 亚洲日本成人在线观看| 久久久综合网| 国产日韩在线不卡| 亚洲你懂的在线视频| 亚洲国产第一|