This paragraph has been concealed! Download the complete document for free! • Click on download to get complete and readable text • This is a free of charge document sharing network • First upload your own document, and you get a word document per email • No registration necessary, gratis Swap homeworks and notes at no charge! Gratis scripts for students and pupils!
b.
typedef
type_def.h
/*** Definition of global types ***/
typedef unsigned char U_INT8;
..
programm.c
#include >type_def.h>
main()
{
U_INT8 variable1, .., variablen;
}
c.
Konstanten
84U à unsigned int 84
84 L à long ing 84
84 UL à unsigned long int 84
1.475e-3F à float
‛A’ à vom typ int (Wert anhand der ASCII Tabelle)
printf(“\”abc\””); à //“abc”
d.
Aufzählungskonstanten
typedef
enum {OFF, ON} KEY; // OFF=0 und ON=1
e.
Variablenvereinbarung
#define MAX_VAL 300 // präprozessoranweisung
const unsigned char test=2; //Wert nach initialisierung
nicht änderbar
volatile unsigned char test=2; // variable bleibt unbeachtet in
Compileroptimierung
f.
Typkonvertierungen
-bei Verknüpfung von Operanden mit unterschiedlichem Datentyp,
ist Datentyp-Umwandlung erforderlich.
i.
Implizite Typkonvertierung
Compiler nimmt automatisch Typkonvertierung vor.
o
für einen Ausdruck gilt u.a.:
-
ist ein Operand long double, werden andere Operanden in long double
konvertiert
-
ist ein Operand double, werden andere Operanden in double
konvertiert
- ist ein Operand float, werden andere
Operanden in float konvertiert
- Operand vom Typ char u. short
werden in int konvertiert
- ist ein Operand long, werden andere
Operanden in long konvertiert
- ist ein Operand unsigned int, werden
andere Operanden in undsigned int konvertiert
o
Beachte:
·
float-Op. Werden nicht automatisch in Typ double
konvertiert
This paragraph has been concealed! Download the complete document for free! • Click on download to get complete and readable text • This is a free of charge document sharing network • First upload your own document, and you get a word document per email • No registration necessary, gratis Swap homeworks and notes at no charge! Gratis scripts for students and pupils!
Ø Integrer –
Erweiterung
o Konvertierung
char, short int in int, wenn int zur Wertaufnahme
ausreicht, sonst in unsigned int
o C definiert nicht,
ob char- Variable Vorzeichen besitzen à
Konvertierung char-Variable in int-Variable maschinenabhängig z.B.:
char val1 = 0x84;
short int val3;
val3 = val1; // val3=0x0084 oder val3=0xFF84
o eindeutige int-Konvert.:
unsigned char val1 = 0x84;
signed char val2 = 0x84;
short int val3;
val3=val1; // val3=0x0084
val3=val2; // val3=0xFF84
ii.
Explizite Typkonvertierung
o Anweisung
Typumwandlung eines Ausdrucks mittels cast-Operator:
(type_name) expression ..
o Typumwandlung
des Wertes von eypression in Typ type_name entsprechender
Typkonvertierungsregeln z.B.:
Bibliotheksfkt. sqrt ( n ) mit n vom Typ double
#include <math.h>
unsigned int m_val;
double result;
result = sqrt ((double) m_val);
o bei Zugriff auf
Absolutadressen ist expl. Typkonvertierung erforderlich
o Beachte:
-int-Werte mit „gr. Bereich“ werden in int-Werte mit „kl. Bereich“ konvertiert,
durch Abschneiden überzähliger Bits von links her
-bei Typumwandlung float in int wird Bruchteil abgeschnitten
- Typkonvertierung double in float ist implementationsabhängig.
g.
Arithmetische Operatoren
% Modulo-Division //
8 % 3 à =2
o Bei division
von int-Werten wird gebrochener teil Abgeschnitten
o Auf float- u.-
double-Werten %-Op, nicht anwendbar
This paragraph has been concealed! Download the complete document for free! • Click on download to get complete and readable text • This is a free of charge document sharing network • First upload your own document, and you get a word document per email • No registration necessary, gratis Swap homeworks and notes at no charge! Gratis scripts for students and pupils!
o
numer. Wert vergleichsoperation:
1: Vergleich trifft zu (true)
0: Vergleich trifft nicht zu (false)
i.
Zuweisungsoperatoren
o expr2 op = expr2 // Äquival.: expr1 = (expr1) op
(expr2)
j.
Logische Operatoren
o && log.
UND
o || log.
ODER
o ! log.
Negation
Negationsoperator ! besitzt Wert:
1 wenn Operand = 0
0 wenn Operand ≠ 0
Test auf ungleich 0 à If (x) statt
if (x!= 0)
Test auf 0 à
If (!x) statt if (x== 0)
if((val1>val2)&&(val3++<val4)) à gefährlich!
Auswertung von links nach rechts, abgebrochen, sobald Resultat feststeht
!!!
k.
Operatoren zu Bit- Manipulation
o
Bit-.Operatoren:
& UND
| ODER
^ Exklusiv – ODER
<< Shift left inbyte <<=0x03 à 3 NULL-Bits von rechts
>> Shift right outbyte >>=0x03 à 3 NULL Bits von links (unsigned)
à Vorzeichen Bit oder NULL Bit bei
(signed)
~ Bit – Komplement
l.
Sonstige Operatoren
o konditionaler
Operator ?:
- Max_temp=(temp1>temp2) ? temp1:temp2;
expr1 ≠ 0: condition true à Berechnung expr2
expr1 = 0: condition false à Berechnung
expr3
àResultatwert ist Wert des ermitt.
Ausdrucks
o Operator sizeof
length=sizeof array;
length=sizeof(long double); à liefert Anzahl an Bytes zur Speicherung
2.
Ein- und Ausgabe
scanf Lesen von Zeichen aus
Standard-Eingabe
fscanf Lesen von Zeichen aus
einer Datei
getchar Lesen eines Zeichens aus
Standard-Eingabe
This paragraph has been concealed! Download the complete document for free! • Click on download to get complete and readable text • This is a free of charge document sharing network • First upload your own document, and you get a word document per email • No registration necessary, gratis Swap homeworks and notes at no charge! Gratis scripts for students and pupils!
fprintf Ausgabe von Zeichen in
Datei
putchar Ausgabe eines Zeichens auf
Standard-Ausgabe
Voraussetzung für Verwendung E/A-Funktionen: #include
<stdio.h>
a.
Funktion scanf
Scanf(“formatangaben“ , &arg1 , &arg2,..);
Scanf(“%d %f %c %x”, &wert, &var,
&zei, &addr); à %d
gehört zu &wert, %c gehört zu &zei ..
b.
Funktion printf
Printf(“formatangaben“, arg1, arg2,
..);Ausgabe Text u. Daten:
z.B.: printf(“Spannung u1: %fV“, u_1);
3.
Kontrollstrukturen
a.
if - / if – else – Anweisung
o
allg. Form:
if (expression)
{
statement_1;
next_statement;
}
else
statement_2;
o ohne {} immer
nur für einen Anweisungsblock gültig
b.
4.2 switch-Anweisung
o allg. Form
switch (expression) switch(x)
{ {
case const_1: statement; case 5: y = 1000;
case const_2: statement; ..
..
case const_n: statement;
default: statement;
}
next statement;
o es gilt
-Wert von expression: int-Typ
-const_i: ganzz. Konstante, konst. Ausdruck
-default ist optional
-mehrere case-Konstanten vor einem statement
-switch-Anw. können verschachtelt werden
-break; Verlassen switch-Anweisung
c.
for-Anweisung:
o allg. Form:
for(expr1; expr2; expr3;)
{
statements;
}
This paragraph has been concealed! Download the complete document for free! • Click on download to get complete and readable text • This is a free of charge document sharing network • First upload your own document, and you get a word document per email • No registration necessary, gratis Swap homeworks and notes at no charge! Gratis scripts for students and pupils! |