[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



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.

*p er altså indholdet af  noget en pointer peger på. p er selve
pointeren, der udmærket kunne starte som &array.

I det aktuelle eksempel kaldes underprogrammet med &value som parameter,
altså adressen på den plads i memory der indeholder value. I
underprogrammet refereres denne som en pointer der skal indeholde value,
altså *value.

Mig bekendt er de mekanikker præcis de samme i c++.

M.v.h.
Søren

John Mørck Hansen wrote:
> 
> Søren H.Sørensen wrote:
> 
> > Det er rigtigt nok, men du kunne godt bare kalde funktionen:
> >
> > void calculate_value( float *value )
> >   {
> >   *value=2.0*5.4;
> >   }
> >
> > I dit main-program bruger du alligevel ikke funktionens returværdi til
> > noget
> 
> Jeps, der er rigtigt men... har man ikke operatoren & i C eller er det kun i
> C++ man kan bruge den operator. Det gør efter mig mening koden mere
> læselig, så man ikke er i tvivl om, at der er tale om en reference!
> 
> (John =;-)
> --
> Din sikre vej til en sikker backup løsning til dit netværk.
> http://www.adilock.dk/~john/
> http://www.adilock.dk


 
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] *