Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Call by reference - Problem bei Aufgabe

Empfohlene Antworten

Veröffentlicht

Zur Aufgabe: Schreiben Sie eine C-Funktion, die den Flächeninalt und den Umfang eines Quadrates mit der zu übergebenden Kantenlänge a an die aufrufende Funktion zurückgibt habe ich folgende Lösung geschrieben.

Ist das folgende richtig?

void umfang(float kante, float* a, float *u)

{

*a=kante*kante;

*u=4*kante;

}

Oder das besser?

void umfang(float *a, float *umfang, float *flaeche)

{

*umfang = ( (*a) * (*a) );

*flaeche = ( 4 * (*a) );

}

Oder ist beides völlig verkehrt?

Danke für alle Antworten!

OK. Danke schonmal. Dann müsste es bei 1. heißen:

void umfang(float kante, float* a, float *u)

{

*a=kante*kante;

*u=4*kante;

}

und bei 2. ie Referenz SO weg?:

void umfang(float *a, float *umfang, float *flaeche)

{

*umfang = ( (a) * (a) );

*flaeche = ( 4 * (a) );

}

Quatsch. Beim ersten natürlich:

void umfang(float *umfang, float *a, float *flaeche)

{

*flaeche=a*a;

*u=4*a;

}

Quatsch. Beim ersten natürlich:

void umfang(float *umfang, float *a, float *flaeche)

{

*flaeche=a*a;

*u=4*a;

}

Hey, danke für die Antwort...also muss es so aussehen und dann entspricht es der Aufgabenstellung?

void umfang(float *u, float a, float *f)

{

*f=a*a;

*u=4*a;

}

Ich würde die Funktion nicht "umfang" nennen, und a als ersten Parameter übergeben, aber auch das sind Stilfragen. Dein Code erfüllt die Aufgabenstellung.

Vielen herzlichen Dank! Hab bei so Übergabe Aufgaben meine Probleme. Bei konkreten Programmieraufgaben krieg ich das irgendwie automatisch hin, aber so theoretisch überlegen is das so ne Sache.

Also danke für die Hilfe!

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.