• <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>
            voip
            風的方向
            厚德致遠,博學(xué)敦行!
            posts - 52,comments - 21,trackbacks - 0
            拼車了,周五晚上五點之后,從杭州濱江到諸暨店口
            posted @ 2016-12-15 17:59 jince 閱讀(1235) | 評論 (0)編輯 收藏
                 摘要: File.cpp函數(shù)定義文件: #include<stdlib.h>#include<stdio.h>#include"File_Head.h"int studentnum=2;student  stud[SIZE];void File_fputc_fgetc(){    FILE ...  閱讀全文
            posted @ 2010-11-01 22:25 jince 閱讀(244) | 評論 (0)編輯 收藏
                 摘要: 一言難盡啊。。。最近發(fā)現(xiàn)一個怪現(xiàn)象。。。浙大門口斑馬線的紅綠燈是只顯示紅燈的。。。綠燈的時候是全黑的。。。難道是培養(yǎng)耐心!??!Link.cpp文件(這個文件主要用來測試鏈表增刪查改函數(shù)): #include<stdio.h>#include"link.h"int main(){    int i;  &n...  閱讀全文
            posted @ 2010-10-31 20:05 jince 閱讀(254) | 評論 (0)編輯 收藏

            值傳遞, 指針傳遞?

            這幾天在學(xué)習(xí)C過程中,在使用指針作為函數(shù)參數(shù)傳遞的時候出現(xiàn)了問題,根本不知道從何得解:源代碼如下:
                createNode(BinNode *tree,char *p)
                {
                    tree = (BinNode *) malloc(sizeof(BinNode));
                    tree->data = *p;
                }
            該代碼段的意圖是通過一個函數(shù)創(chuàng)建一個二叉樹的節(jié)點,然而在,調(diào)用該函數(shù)后,試圖訪問該節(jié)點結(jié)構(gòu)體的成員時候,卻發(fā)生了內(nèi)存訪問錯誤,到底問題出在哪兒呢?

            一直不明白指針作為函數(shù)參數(shù)傳值的機制,翻開林銳的《高質(zhì)量C/C++編程指南》,找到了答案。

                [如果函數(shù)的參數(shù)是一個指針,不要指望用該指針去申請動態(tài)內(nèi)存]
                
            原來問題出在C編譯器原理上:編譯器總是要為函數(shù)的每個參數(shù)制作臨時副本,指針參數(shù)tree的副本是 _tree,編譯器使 _tree = tree。如果函數(shù)體內(nèi)的程序修改了_tree的內(nèi)容,就導(dǎo)致參數(shù)tree的內(nèi)容作相應(yīng)的修改。這就是指針可以用作輸出參數(shù)的原因。
            即上面的函數(shù)代碼經(jīng)過編譯后成為:
                createNode(BinNode *tree,char *p)
                {
                    BinNode *_tree;
                    _tree = tree;
                    _tree = (BinNode *) malloc(sizeof(BinNode));
                    _tree->data = *p;
                }
            如果沒有
                _tree = (BinNode *) malloc(sizeof(BinNode));
            這個語句,在函數(shù)體內(nèi)修改了_tree的內(nèi)容,將會導(dǎo)致參數(shù)tree的內(nèi)容作相應(yīng)的修改,因為它們指向相同的內(nèi)存地址。而
                _tree = (BinNode *) malloc(sizeof(BinNode));
            這個句,系統(tǒng)重新分配內(nèi)存給_tree指針,_tree指針指向了系統(tǒng)分配的新地址,函數(shù)體內(nèi)修改的只是_tree的內(nèi)容,對原tree所指的地址的內(nèi)容沒有任何影響。因此,函數(shù)的參數(shù)是一個指針時,不要在函數(shù)體內(nèi)部改變指針所指的地址,那樣毫無作用,需要修改的只能是指針所指向的內(nèi)容。即應(yīng)當把指針當作常量。

            如果非要使用函數(shù)指針來申請內(nèi)存空間,那么需要使用指向指針的指針
                createNode(BinNode **tree,char *p)
                {
                    *tree = (BinNode *) malloc(sizeof(BinNode));
                }
            上面的是林銳的說法,目前來說不知道怎么去理解,不過可以有另外的方案,通過函數(shù)返回值傳遞動態(tài)內(nèi)存:
                BinNode *createNode()
                {
                    BinNode *tree;
                    tree = (BinNode *) malloc(sizeof(BinNode));
                    return tree;
                }
            這個倒還說得過去,因為函數(shù)返回的是一個地址的值,該地址就是申請的內(nèi)存塊首地址。但是,這個容易和另外的一個忠告相混繞
                [不要用return語句返回指向“棧內(nèi)存”的指針,因為該內(nèi)存在函數(shù)結(jié)束時自動消亡]

            這里區(qū)分一下靜態(tài)內(nèi)存,棧內(nèi)存和動態(tài)分配的內(nèi)存(堆內(nèi)存)的區(qū)別:
            (1) 從靜態(tài)存儲區(qū)域分配。內(nèi)存在程序編譯的時候就已經(jīng)分配好,這塊內(nèi)存在程序的整個運行期間都存在。例如全局變量,static變量。
            (2) 在棧上創(chuàng)建。在執(zhí)行函數(shù)時,函數(shù)內(nèi)局部變量的存儲單元都可以在棧上創(chuàng)建,函數(shù)執(zhí)行結(jié)束時這些存儲單元自動被釋放。棧內(nèi)存分配運算內(nèi)置于處理器的指令集中,效率很高,但是分配的內(nèi)存容量有限。
            (3) 從堆上分配,亦稱動態(tài)內(nèi)存分配。程序在運行的時候用malloc或new申請任意多少的內(nèi)存,程序員自己負責在何時用free或delete釋放內(nèi)存。動態(tài)內(nèi)存的生存期由我們決定,使用非常靈活,但問題也最多。

            因此,試圖返回一個棧上分配的內(nèi)存將會引發(fā)未知錯誤
                char *GetString(void)
                {
                    char p[] = "hello world";
                    return p; // 編譯器將提出警告
                }
            p是在棧上分配的內(nèi)存,函數(shù)結(jié)束后將會自動釋放,p指向的內(nèi)存區(qū)域內(nèi)容不是"hello world",而是未知的內(nèi)容。
            如果是返回靜態(tài)存儲的內(nèi)存呢:
                char *GetString(void)
                {
                    char *p = "hello world";
                    return p;
                }
            這里“hello world”是常量字符串,位于靜態(tài)存儲區(qū),它在程序生命期內(nèi)恒定不變。無論什么時候調(diào)用GetString,它返回的始終是同一個“只讀”的內(nèi)存塊。
             
            [參考:林銳《高質(zhì)量C/C++編程指南》]

            posted @ 2010-10-31 19:32 jince 閱讀(693) | 評論 (0)編輯 收藏

            1、結(jié)構(gòu)體內(nèi)存分配按照最嚴格的數(shù)據(jù)類型分配
            例:
             struct  student
             {
              int num;
              char c;
             };
             struct student stu1,stu2,stus[20],*ps;

            內(nèi)存分配的時候按照int型分配(地址按照能被4整除),成員的排列次序不同,內(nèi)存分配不同。。。
            另外編譯器影響結(jié)構(gòu)體的內(nèi)存分配。。最有效的方式(sizeof(student))計算字節(jié)數(shù)。。


             struct  student
             {
              int num;
              char name[20];
             }stu1,stu2,stus[20],*ps;

                    struct
             {
              int num;
              char  name[20];
             }stu1;//沒有結(jié)構(gòu)體名稱,所以不能在其他地方定義變量。。

             

            無語。。


            2、結(jié)構(gòu)體可以嵌套,但是結(jié)構(gòu)體不能嵌套自身。。。

               Linux定義:  Linux is not unix?。?!

               struct student li,zhang={"zhang",1,2,3};

             li=zhang;//結(jié)構(gòu)體可以直接相等。。當然兩個不同的結(jié)構(gòu)體變量不能直接賦值。。。
             li={"li",1,2,3};//錯。。
             if(stu1==stu2);//錯。。

                    struct student
             {
             int age;
             char *name;
             }*ps;
             ps=(struct student *)malloc(sizeof(struct student));
             (*ps).age=30;
             (*ps).name=(char *)malloc(20);
             strcpy((*ps).name,"jince");
             free((*ps).name);//釋放順序。。。
             free(ps);

            3、海賊王更新。。。

            4、typedef int intage;
               typedef double real;
               #define int intage;
               #define char* string;
               string s1,s2;//這時候存在問題。。。  char* s1,s2;。。。
               typedef char* string;
               string s1,s2;//OK
               typedef  int bool;
               struct Rec
               {
             ... 
             };

                typedef struct Rec Rec;

               Rec jince;
              
               指針變量統(tǒng)一占4個字節(jié)。。。
             
               指針數(shù)組。。。解決鏈表問題??
               前一個節(jié)點記錄后一個節(jié)點的地址。。。。

             typedef  struct  Link
             {
              int a;
              char c;
              Link *next; 
             }Link;


            5、#ifndef  LIST_H   //預(yù)編譯命令。。。對于已經(jīng)定義的LIST_H不進行編譯。。

             

             

            posted @ 2010-10-30 20:31 jince 閱讀(249) | 評論 (0)編輯 收藏
                       str_cat()函數(shù)自定義:
            #include<stdio.h>
            char * str_cat(char *s1,char *s2)
            {
                
            char *s;
                s
            =(char *)malloc(strlen(s1)+strlen(s2)+1);
                strcpy(s,s1);
                strcpy(s
            +strlen(s1),s2);
                
            return s;
            }

            int main()
            {
                
            char s1[10],s2[10];
                
            char *s3;
                
            while(scanf("%s %s",s1,s2)!=EOF)
                
            {
                    s3
            =str_cat(s1,s2);
                    puts(s3);
                }

                
            return 0;
            }
             
               報數(shù)題:
            #include<stdio.h>
            #include
            <stdlib.h>
            #include
            <string.h>
            int main()
            {
                
            int s[100];
                
            int n,m,i,j,temp,k,g;
                
            while(scanf("%d%d%d",&n,&m,&g)!=EOF)//n為總?cè)藬?shù),m為開始報數(shù)人序號,g為報數(shù)循環(huán)數(shù) 
                {
                    
            int j=m;
                    memset(s,
            0,sizeof(s));
                    
            for(i=1;i<n;i++)
                    
            {
                        temp
            =0;
                        
            while(temp<g)
                        
            {
                            
            if(s[j]==0)
                                temp
            ++;
                            
            if(temp==g)
                                
            break;
                            j
            ++
                            
            if(j>n)
                            
            {
                                
            for(k=1;k<=n;k++)
                                    
            if(s[k]==0)
                                    
            {
                                        j
            =k;
                                        
            break;
                                    }

                            }

                        }

                        s[j]
            =1;
                    
            //    printf("%d\n",j);
                        for(k=1;k<=n;k++)
                        
            {
                                printf(
            "%d ",s[k]);
                        }

                        printf(
            "\n");
                    }

                    
            for(k=1;k<=n;k++)
                    
            {
                        
            if(s[k]==0)
                        
            {
                                printf(
            "最后留下同學(xué)序號:%d\n",k); 
                                
            break;
                        }

                    }


                }

                
            return 0;
            }

            一個五位數(shù)*4=這個數(shù)的逆序題:
            #include<math.h>
            #include
            <stdio.h>
            #include
            <stdlib.h>
            #include
            <string.h>
            void Numtostring(int num,char s[])  //自定義數(shù)字轉(zhuǎn)換成字符串函數(shù) 
            {
                
            int temp,i=0;
            //    char *s;
            //    s=(char *)malloc(500); 
                
            //char s[500];
                while(num!=0)
                
            {
                    temp
            =num%10;
                    s[i]
            =temp+48;
                    i
            ++;
                    num
            =num/10;    
                }

                s[i]
            ='\0';
                strrev(s);
            }

            int main()
            {
                
            int i;
                
            int num;
                
            char s[500],s0[500];
                
            for(i=10000;i<100000;i++)
                
            {
                    num
            =i*4;
                    
            //printf("%d\n",num);
                    Numtostring(i,s);
                    Numtostring(num,s0);
                
            //    printf("%s\n",s);
                    strrev(s0);
                    
            if(strcmp(s,s0)==0)
                    printf(
            "%d*4=%s\n",i,strrev(s));
                                
                }

                
            return 0;
            }
             

            posted @ 2010-10-29 20:28 jince 閱讀(165) | 評論 (0)編輯 收藏
                 今天培訓(xùn)的老師讓我們做的題目。。。
                 我寫了幾個(不多說了比較累直接上代碼了):
            #include<stdio.h>
            #include
            <string.h>
            #include
            <math.h>
            #include
            <stdlib.h>
            void Numtostring(int num,char s[])  //自定義數(shù)字轉(zhuǎn)換成字符串函數(shù) 
            {
                
            int temp,i=0;
            //    char *s;
            //    s=(char *)malloc(500); 
                
            //char s[500];
                while(num!=0)
                
            {
                    temp
            =num%10;
                    s[i]
            =temp+48;
                    i
            ++;
                    num
            =num/10;    
                }

                s[i]
            ='\0';
                strrev(s);
            }

            int NumberTest0(int num)  //數(shù)字逆序,返回逆序值 
            {
                
            int temp;
                
            int n,i;
                
            int num0=0;
                n
            =log10(num);
                printf(
            "n=%d\n",n);
                
            for(i=n;i>=0;i--)
                
            {
                    temp
            =num%10;
                    num
            =num/10;
                    num0
            +=temp*pow(10,i);
                    printf(
            "num0=%d\n",num0);
                }

                
            return num0;    
            }

            int StringTest(int num)//回文判斷,字符串逆轉(zhuǎn)思路 
            {
                
            char s[500],s1[500];
                Numtostring(num,s);
            //數(shù)字轉(zhuǎn)換成字符串函數(shù) 
                puts(s);
                strcpy(s1,s);
                strrev(s1);
                
            if(strcmp(s1,s)==0)
                    printf(
            "Yes\n");
                
            else
                    printf(
            "No\n");
                
            return 0;
            }


            int NumberTest1(int n)//回文判斷 老師解題思路 聽說是大神級的人物寫的。。。
            {
                
            int temp=0;
                
            int m=n;
                
            while(n)
                
            {
                    temp
            =temp*10
                    temp
            +=n%10;
                    n
            =n/10;
                }

                printf(
            "%d\n",temp);
                
            if(temp==m)
                    printf(
            "Yes\n");
                
            else
                    printf(
            "No\n");
                
            return 0;
            }

            int main()
            {

                
            int num,num0;
            //    long n;
                char s[500];
                
            while(scanf("%d",&num)!=EOF)
                
            {
                  
            /*num0=Test(num);
                    printf("%d\n",num0);
                    if(num0==num)
                        printf("Yes\n");
                    else
                        printf("No\n");
            */

                
            //    Numtostring(num,s);
                
            //    puts(s);
                
            //    StringTest(num); 
                    NumberTest1(num);
                }

                
            return 0;
            }
             


                
            posted @ 2010-10-29 19:57 jince 閱讀(639) | 評論 (0)編輯 收藏
                           經(jīng)過這一個月的找工作生涯,我知道有一項能力是那么重要,無論走到哪里都會問我有什么經(jīng)驗。。這使我很壓抑?。?!
            posted @ 2010-10-26 19:55 jince 閱讀(212) | 評論 (0)編輯 收藏
                              還想拆了再裝。。。
            posted @ 2010-10-21 20:57 jince 閱讀(166) | 評論 (0)編輯 收藏
                              在家里一直投簡歷,面試,等待??!
            今天又去了,總結(jié)一下心得:
                             1)在家沒事學(xué)點東西,不要求精但是要廣。。
                             2)一些基礎(chǔ)的東西要記住,不要像我連blog的地址也記不住。。(今天很尷尬?。。。?br>                 3)以前學(xué)過的東西最好能夠記錄下來可以溫習(xí)一下,說不定哪天就能用上。。。
                             4)多出去走走,不期望撿到金子,但是可以給你創(chuàng)造的靈感(我去面試過很多公司了,感覺很不一樣)。。。
            posted @ 2010-10-20 11:01 jince 閱讀(257) | 評論 (0)編輯 收藏
            僅列出標題  下一頁
            哈哈哈哈哈哈
            欧美日韩成人精品久久久免费看 | 久久国产一片免费观看| 香蕉99久久国产综合精品宅男自 | 久久受www免费人成_看片中文| 久久丫精品国产亚洲av不卡| 国产午夜精品久久久久免费视| 国产一区二区精品久久凹凸| 人妻无码精品久久亚瑟影视 | 青青草原综合久久大伊人导航| 99久久无码一区人妻a黑| 中文国产成人精品久久不卡| 热99re久久国超精品首页| 亚洲中文久久精品无码ww16| 精品久久久久一区二区三区| 久久久久久亚洲精品成人| 狠狠色噜噜色狠狠狠综合久久| 久久免费香蕉视频| 国产精品美女久久福利网站| 国产精品久久久久一区二区三区| 91精品国产91久久久久福利| 久久人做人爽一区二区三区| 99久久综合国产精品二区| 久久久久久a亚洲欧洲aⅴ| 国内精品久久久久久99| 久久午夜羞羞影院免费观看| 色婷婷久久综合中文久久一本| 热RE99久久精品国产66热| 国产精品久久久久蜜芽| 狠狠色丁香久久婷婷综合蜜芽五月 | 久久人人爽人人澡人人高潮AV | 伊人丁香狠狠色综合久久| 91精品国产综合久久四虎久久无码一级| 久久免费线看线看| 一级女性全黄久久生活片免费 | 久久国产欧美日韩精品| 久久久久亚洲精品天堂| 狠狠狠色丁香婷婷综合久久俺| 麻豆精品久久久一区二区| 久久99国产精品成人欧美| 无码人妻少妇久久中文字幕| 麻豆国内精品久久久久久|