[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: [CPROG] pass by reference



Hej Søren

Det er ikke rigtigt. Et array navn er blot en pointer til det første element 
i array'et.

Mao. er erklæringerne

char s[];

og

char *s;

ekvivalente.

Så uanset om du erklærer
char string[] = "dette er en streng";
eller
char *string = "dette er en streng";

så vil du få samme resultat med
printf("%s", string);
eller for den sags skyld med
printf("%S", &string[0]);

mvh
Henrik


Søren H.Sørensen wrote:

> Jo man har da & OGSÅ, men & giver adressen af et eller andet element,
> mens * refererer til indholdet i en adresse.
> 
> Eksempel:
> char string[50]="dette er en string";
> 
> Skal den refereres efterfølgende skal man bruge &-operatoren. Fx:
> printf( "%s", &string );
> 
> Havde man i stedet erklæret den som:
> char *string = "dette er en string"; Så havde "string" været en pointer
> til et sted der indeholdt strengen og den kunne have været printf'et
> uden yderligere.
> 
<snip>


 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 20:09 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] *