[C語言面試編程題]java面試編程題_第1頁
[C語言面試編程題]java面試編程題_第2頁
[C語言面試編程題]java面試編程題_第3頁
[C語言面試編程題]java面試編程題_第4頁
免費預覽已結束,剩余1頁可下載查看

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

1、c語言面試編程題java面試編程題 在c語言中,輸入和輸出是經由標準庫中的一組函數(shù)來實現(xiàn)的。在ansi/iso c中,這些函數(shù)被定義在頭文件;中。下面就由為大家介紹一下c語言面試編程題的文章,歡迎閱讀。 c語言面試編程題篇1 考查的是結構體和數(shù)組的內存布局狀況。 #include #include typedef struct array1 int id; struct array1* next; a; typedef struct array2 int id; int a; int b; int c; * b; int main() a s115; a* s2; b s3; for(int

2、i=0;i10;i+) s1i.id=i+64; s2=s1+3; s3=(b)s2; printf(%d/n,s3-b); return 0; c語言面試編程題篇2 從字符串數(shù)組和指針字符串在內存中的安排狀況考查指針的用法。 #include #include #include char *getmemory(char *p) p = (char *)malloc(100); return p; /當調用此函數(shù)時,會在棧里安排一個空間存儲p, p指向堆當中的一塊內存區(qū),當函數(shù)調用結束后,若函數(shù)沒有返回值, /系統(tǒng)自動釋放棧中的p void test(void) char *str = nul

3、l; str=getmemory(str); strcpy(str, test); printf(%s/n,str); char *getmemory1(void) char *p = test1; return p; /若換成char p=hello world; 就會在函數(shù)調用結束后,釋放掉為test1的拷貝安排的空間,返回的p只是一個野指針 void test1() char *str = ; str=getmemory1(); printf(%s/n,str); /str=getmemory(); void getmemory2(char *p, int num) *p = (char

4、 *)malloc(num); /當調用此函數(shù)時,會在棧里安排一個空間存儲p, p指向棧中的一變量str,在此函數(shù)中為str在堆當中安排了一段內存空間 /函數(shù)調用結束后,會釋放p, 但str所在的函數(shù)test2還沒運行完,所以str此時還在棧里. void test2(void) char *str = null; getmemory2(str, 100); strcpy(str, hello); printf(%s/n,str); void test3(void) char *str=(char *)malloc(100); strcpy(str, hello);/此時的str指向的是拷貝到

5、棧里的hello,所以當釋放掉str指向的堆空間時,str指向的棧里的值還是不變 free(str); if(str != null) strcpy(str, world); printf(%s/n,str); int main() test(); test1(); test2(); test3(); c語言面試編程題篇3 c語言中sizeof的用法 void fun(char s10) printf(%s/n,s); printf(%d/n,sizeof(s);/引用的大小 int main() char str=sasdasdes; printf(%d/n,sizeof(str);/字符串數(shù)組的大小10(包含了字符/0) printf(%d/n,strlen(str);/字符串的長度9 char *p=str; printf(%d/n,sizeof(p);/指針的大小4 printf(%d/n,strlen(p);/字符串的長度9 fun(str); void *h=malloc(100); char ss100=abcd; printf(%d/

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
  • 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論