2016年計(jì)算機(jī)軟件水平考試軟件設(shè)計(jì)考前練習(xí)題

字號(hào):

1.設(shè)有代碼"int(*ptr)[10];”,其中的ptr是( )
    ①10個(gè)指向整型變量的指針
    ②指向10個(gè)整型變量的函數(shù)指針
    ③一個(gè)指向具有10個(gè)元素的一維數(shù)組的指針
    ④具有10個(gè)指針元素的一維數(shù)組
    2.若有以下定義,則數(shù)值為4的表達(dá)式是( )
    int w[3][4]={{0,1},{2,4},{5,8}},(* p)[4]= W;
    ①*w[1]+l ?、趐++,*(p+1) ?、踳[2][2] ?、躳[1][1]
    【解】代碼“int(*ptr)[10];”的分析過程是,因圓括號(hào),括號(hào)內(nèi)的ptr先與字符*結(jié)合,字符*修飾標(biāo)識(shí)符ptr是一種指針;接著與后面的一對方括號(hào)結(jié)合,表示是這樣的一種指針,是指向一維數(shù)組的;再有方括號(hào)中的10,說明這種數(shù)組有10個(gè)元素。至此,ptr是指向含10個(gè)元素的一維數(shù)組的指針。最后,是最前面的int,表示數(shù)組元素是int類型的。所以,ptr是一個(gè)指向具有10個(gè)int型元素的一維數(shù)組的指針。所以解答是 ③。另外,要是①,10個(gè)指向整型變量的指針,就是一個(gè)指針數(shù)組,上述代碼應(yīng)寫成“int *ptr[10];”,即ptr是一個(gè)有10個(gè)指向整型變量的數(shù)組。要是②,返回值是指向10個(gè)整型變量的函數(shù)的指針,上述代碼應(yīng)寫成“int(* (*ptr)())[10];”,即ptr是指針,指向一種函數(shù),函數(shù)的返回值又是一種指針,指向10個(gè)元素的數(shù)組,數(shù)組的元素是整型的。下面的代碼是這樣的函數(shù)指針和函數(shù)的例子:
    # include
    int a[][10]={{1,2,3,4,5,6,7,8,9,0} ,{0,1,2,3,4,5,6,7,8,9} };
    int(*(*ptr)(int))[10];
    int(*f( int n))[10]
    {return a+n;
    }
    void main()
    { int(*p)[10],*q;
    ptr=f;/*讓ptr指向函數(shù)f*/
    P=(*ptr)(0);
    q=*p;
    printf("%d\n", *p);
    P=(*ptr)(l);
    q=*p;
    printf("%d\n", *q);
    }
    在上述代碼中,函數(shù)有一個(gè)int型的形參。要是④,其意義與①相同,上述代碼應(yīng)寫成“int* ptr[10];”,即 ptr是一個(gè)有10個(gè)元素的數(shù)組,數(shù)組元素是指向整型變量的指針。
    【解】二維數(shù)組定義有多種賦初值的辦法,問題給出的代碼是按行給數(shù)組的部分元素賦初值。它們分別是w[0][0]=0.w[0][1]=1、w[1] [1]=2.w[1][1]=4,w[2][0]=5,w[2][1]=8。根據(jù)約定,未指定初值的元素自動(dòng)置全0值。指針變量p是一個(gè)指向具有四個(gè) int型元素的一維數(shù)組的指針,定義時(shí)的初值使它指向數(shù)組W的第一行。①的代碼,*w[1]+1中的W[l]是指向 w[l][0]的指針,*w[1] 就是w[1][0],其值是2,*w[1]+l的值是3。②的代碼是逗號(hào)表達(dá)式,“p++,*(p+1)”先使p指向數(shù)組w的第二行,*(p+l)中的 p+l是指向數(shù)組w的第三行,*(p+1)是指針值,指向數(shù)組w的第三行的第一個(gè)元素,即&w[2][0]. ③的代碼w[2][2]引用數(shù)組W第三行的第三列元素,其值是0。④的代碼p[1][l]引用數(shù)組W第二行的第二列元素w[1][1],其值是 4。所以解答是@。
    Networks can be interconnected by different devices in the physical layer networks can be connected by _(1)_ or hubs .which just move the bits from one network to an identical network. One layer up we find bridges and switches which operate at data link layer. They can accept _(2)_ examine the MAC address and forward the frames to a different network while doing minor protocol translation in the process in me network layer ,we have routers that can connect two networks, If two networks have _(3)_ network layer, the router may be able to translate between the packer formats. In the transport layer we find transport gateway, which can interface between two transport connections Finally, in the application layer, application gateways translate message _(4)_ .As an example, gateways between Internet e-mail and X.400 e-mail must _(5)_ the e-mail message and change various header fields.
    (1)A.reapers  B.relays  C.packages  D.modems
    (2)A.frimes  B.packets  C.packages  D.cells
    (3)A.special  B.dependent  C.similar  D.dissimilar
    (4)A.syntax  B.semantics  C.language  D.format
    (5)A.analyze  B.parse  C.delete  D.create
    參考答案:A A D B B