[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: [PROGRAMMERING] malloc ter sig underligt



Anders Melchiorsen <sslug@sslug> writes:

>> int** find_numbers(int tal);
>
> Hvorfor dog dobbelt-pointer, er der noget tjent ved det? Et
> nul-afsluttet array er vel lige så godt i denne situation, men giver
> væsentlig mindre arbejde?

Hvis jeg kun har en int* kan jeg ikke finde slutningen af arrayet. Der
er ikke nogen værdi af typen int der udtrykker at arrayet er slut. Vi
kan selvfølgelig antage at vi ved noget om find_numbers så vi ved at
den ikke kan returnerer et 0 og vi derfor kan bruge det som
stop-værdi.

Strengfunktioner kan bruge char*. Det skyldes at vi ved (har vedtaget)
at \000 er stop-værdi. Strenge kan ikke indeholde null-tegnet og
dermed kan de enkelte elementer i et char-array have en værdi ud over
dem vi accepterer.

>> int **pointer;
>> pointer = find_numbers;
>> while(pointer != NULL) {
>>     printf("%d\n",**pointer)
>>     pointer++;
>> }
>
> Der mangler vist lige en stjerne foran "pointer" i while-linjen.

Nej.

-- 
 Peter Makholm     |     If you can't do any damage as root, are you still
 sslug@sslug |                                          really root?
 http://hacking.dk |                       -- Derek Gladding about SELinux


 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 22:44 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *