11. März 2015
Daniel Hentzen
dhentzen@student.ethz.ch

3 Methoden, um Variablen zuzuweisen :
#include<iostream>#include<stdlib.h>...float a = atof( argv[1] )
t_f = 9 / 5 * t_c + 32; // FALSCH !!t_f = (9 / 5) * t_c + 32; // FALSCH !!
t_f = (9 * t_c) / 5 + 32; // RICHTIG !t_f = (9.0f / 5) * t_c + 32; // RICHTIG !t_f = (9f / 5) * t_c + 32; // FALSCH !t_f = float(9) / 5 * t_c + 32; // RICHTIG !


char x = 'y';
float a = 3.14;float x = 0.1E-4;
9.0f / 5 //9 wird als float abgespeichert
bool test1 = 10; // test 1 = truebool test2 = 0; // test 2 = false


int a; // Definitiona = 5; // Zuweisungint b = 3; // Definition und Zuweisungint c,d,e; // in Seriec = d = e = 7;
int a!;int ä;int 1a;int for;int main;int __a:int _B;
<modifier> <type> <name>;
long int a; // integer Variable a mit 2 x 2 Byte = 4 Byte Speicherplatzshort int b; // integer Variable b mit 1 Byte Speicherplatzunsigned int c; // c ohne Vorzeichenconst int d = 5; // d hat im ganzen Programm den Wert 5
float a = 3.14;int b = a; // a = 3int a = 3;float b = a; // b = 3.0
char a = 'q';int b = a; // b entspricht dem ASCII Code von 'q'
int / float / double --> char
int a = 127;char b = a; // b ist das ASCII Zeichen von 127
! Achtung : ergibt falsche Werte für Werte über 255 !
int / float / double --> bool
int a = 0;bool b = a; // b = FALSE (0)int a = 2;bool b = a; // b = TRUE (1)
bool --> int / float / double
bool a = true;int b = a; // a = 1bool a = false;int b = a; // a = 0
long int a = 100000000000000;int b = a; // falsche Werte!!long int a = 10000000000000;short int b = a; // falsche Werte
Bits werden abgeschnitten, ergibt falsche Werte für grosse Zahlen
float a = 3.14;long int b = a; // a wird abgerundet
OK!
(<type>) Wert/Variable; // C und C++<type> (Wert/Variable); // nur in C++float f = float(3/2 + 4.0f); // f=5.0float f = float(3)/2 + 4.0f; // f=5.5
float a = sqrt(81); // "function call", a = 9
float b = atof("32"); // b = 32
<type> <name> ( <type> ) // Prototyp
Funktionskopf :
<type> <name>(arguments)
{ statements;return <Wert/Variable>; // (optional)}
float t_umwandlung(float); // Deklaration, Prototypint main(){...}float t_umwandlung(float t_c) //Definition{...}
<name> (argument1, argument2,...)float c;cin >> c;float f;f = t_umwandlung(c); // function call

