1 / 12

Informatik Grundlagen, WS04, Seminar 7 Informatik

Informatik Grundlagen, WS04, Seminar 7 Informatik. Allgemeines. Besprechung „Unvollständige Spezifikation“ im Übungsblatt Übungsblatt Mittwoch oder Donnerstag?. 2-dimensionale Felder. Matrix int myMatrix[ROWS][COLUMNS]. Funktionen. Immer Return Value angeben

connie
Download Presentation

Informatik Grundlagen, WS04, Seminar 7 Informatik

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Informatik Grundlagen, WS04, Seminar 7 Informatik

  2. Allgemeines • Besprechung „Unvollständige Spezifikation“ im Übungsblatt • Übungsblatt Mittwoch oder Donnerstag?

  3. 2-dimensionale Felder • Matrix • int myMatrix[ROWS][COLUMNS]

  4. Funktionen • Immer Return Value angeben • auch wenn standardmäßig int als return wert • also int myFunc()… • nicht myFunc()… • Wenn in Funktion verschiedene Zweige (durch if-else) müssen alle Zweige Return Value zurückgeben! • Normalerweise aber sowieso nur ein Ausstiegspunkt • void myProc() ist Prozedur

  5. main • main hat auch Rückgabewert. • int main() {… • Dieser kann von Win(DOS) batch file verwendet werden. • errorlevel • Auch Linux/ Unix kann Rückgabewert in shell scripts verwenden • $?

  6. Call by value • Tafel: Funktion max int main () { int a,b printf („%d“,max (a,b)); } int max(int x, int y) { … } • Jede Funktion hat eigenen Speicher für lokale Variablen • Demo: Debugger. Gültigkeitsbereich von Vars. • Demo projekt test4: zech expo funktion

  7. Call by value • Was ist das? • Probieren sie swap-Funktion: • vertauscht x und y; int swap (int x, int y) { int temp = x; x=y; y=temp; } main() { int a=4; int b=5; swap (a,b); }

  8. Parameterübergabe • Aktualparameter • Formalparameter • Zuweisungskompatibilität • Typen von Aktualparameter und Formalparameter müssen zusammenpassen. • sonst castet der compiler. • bsp: intmyFunc (int iPar) {…} main () { myFunc(2.0) }

  9. Umwandeln String in Integer • Dasselbe Prinzip wie in Übung 2: Binärzahl umwandeln in Dezimalzahl.

  10. Deklaration - Defínition • Unterschied? • Compiler benötigt Deklaration • Linker benötigt Definition • #include <stdio.h> • ist eine Forward Deklaration von printf • Definition ist in anderer Bibliothek/ Datei • Demo projekt test4: zech expo funktion • auskommentieren von Dekl. /Def.

  11. tipps • Visual Studio • Consolen Fenster ist nach Programmaufruf sofort wieder weg. • Abhilfe: Ctrl F5 statt F5: Start without Debugging

  12. Aufgabe: Matrix • Matrix mit Skalar multiplizieren. • Erklärung Tafel. Weitere Aufgabe : eigenes strcmp

More Related