All pastes #284084 Raw Edit

Something

public text v1 · immutable
#284084 ·published 2006-12-18 21:13 UTC
rendered paste body
/*
  Beispiel für "call by refence" ohne Rückgabewert
  Negiert eine Integerzahl
*/

#include <stdio.h>

void negInt(int *);		// Deklaration der Negierungs-Funktion

int main() {

	int iZahl;

	printf("Bitte Zahl eingeben: ");
	scanf("%d", &iZahl);
	fflush(stdin);

	// Warum muss das schon hier vor dem Funktionsaufruf stehen?
	printf("\n%d negiert ergibt ", iZahl);

	negInt(&iZahl);

	printf("%d.\n\n", iZahl);

	return 0;
}

/*
 Negiert einen Integerwert
 Aufruf:	negInt(&iZ)

 Parameter:
 int * iZ	übergebener Wert

 Rückgabetyp:
 void		keine Rückgabe
 */

void negInt(int * iZ) {
	// Vorrang * und - hier gleich, deshalb Auswertung von rechts nach links
	*iZ = -*iZ;
}