100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached
logo-home
Samenvatting Industrieel ingenieur - 2e bach - Programmeren in C en C plusplus $4.31   Add to cart

Summary

Samenvatting Industrieel ingenieur - 2e bach - Programmeren in C en C plusplus

 54 views  1 purchase
  • Course
  • Institution

Uitgebreide samenvatting van C Alles wat in les werd gezegd, werd er bijgeschreven

Preview 8 out of 51  pages

  • August 3, 2020
  • 51
  • 2019/2020
  • Summary
avatar-seller
PROGRAMMEREN IN C
PROGRAMMEREN IN C EN C++ (2019 – 2020)


INHOUDSOPGAVE


HOOFDSTUK 1 – BASISCONCEPTEN IN C ............................................................................................ 4


SITUERING PROGRAMMEERTAAL C ............................................................................................................ 4
EERSTE C-PROGRAMMA.......................................................................................................................... 4
COMMENTAAR ...................................................................................................................................... 4
RETURN 0 ............................................................................................................................................ 4
PROCUDURELE TAAL ............................................................................................................................... 4
PROGRAMMASTRUCTUUR ....................................................................................................................... 5
PREPROCESSING DIRECTIVES ..................................................................................................................... 5
VARIABELEN EN FUNDAMENTELE DATATYPES .............................................................................................. 5
VARIABELEN DECLAREREN ........................................................................................................................ 5
FUNDAMENTELE DATATYPES IN C .............................................................................................................. 6
GEHELE TYPES ....................................................................................................................................... 6
LITERALS .............................................................................................................................................. 7
CONSTANTEN ........................................................................................................................................ 8
IMPLICIETE CONVERSIES........................................................................................................................... 8
EXPLICIETE CONVERSIES – CASTEN ............................................................................................................. 8
OPERATOREN ....................................................................................................................................... 9
OPERATOREN ........................................................................................................................................ 9
REGELS AUTO-(IN/DE)CREMENT OPERATOREN .............................................................................................. 9
CONDITIONELE UITDRUKKING .................................................................................................................... 9
CONTROLESTRUCTUREN ........................................................................................................................ 10
HERHALINGSSTRUCTUUR ........................................................................................................................ 10
SELECTIESTRUCTUUR ............................................................................................................................. 10
VERSCHILLENDE CONTROLESTRUCTUREN C EN JAVA ..................................................................................... 10
ELEMENTAIRE I/O ............................................................................................................................... 10
UITVOER ............................................................................................................................................ 10
INVOER.............................................................................................................................................. 11
GETCHAR/PUTCHAR (IN <STDIO.H>) ......................................................................................................... 11
FUNCTIES ........................................................................................................................................... 12
DEFINITIES FUNCTIES ............................................................................................................................ 12
DECLARATIE FUNCTIES ........................................................................................................................... 12
OPROEPEN VAN FUNCTIES: CALL BY VALUE ................................................................................................. 13
RECURSIEVE FUNCTIES........................................................................................................................... 13
ARRAYS EN TOEPASSINGEN.................................................................................................................... 14
WAT ZIJN ARRAYS?............................................................................................................................... 14
DECLARATIE VAN ARRAY ........................................................................................................................ 14



1

,GEBRUIK VAN ARRAY ............................................................................................................................ 14
INITIALISATIE BIJ DECLARATIE VAN ARRAYS ................................................................................................. 15
ARRAYS ALS FUNCTIEPARAMETERS ........................................................................................................... 15
TOEPASSINGEN OP ARRAYS..................................................................................................................... 16


HOOFDSTUK 2: POINTERS ............................................................................................................... 19


POINTERS: ALGEMEEN .......................................................................................................................... 19
NULLPOINTER ...................................................................................................................................... 19
VOIDPOINTER...................................................................................................................................... 19
CALL BY REFERENCE .............................................................................................................................. 20
POINTERS EN ARRAYS ........................................................................................................................... 20
POINTER NAAR CONST .......................................................................................................................... 22
BEWERKINGEN OP POINTERS = SCHUIVENDE POINTERS ................................................................................ 23
POINTER ALS FUNCTIERESULTAAT ............................................................................................................ 24
CONSTANTE POINTER............................................................................................................................ 24
FUNCTIE-POINTERS .............................................................................................................................. 25
ARRAY VAN FUNCTIE-POINTERS ............................................................................................................... 25
FUNCTIE-POINTER ALS PARAMETER .......................................................................................................... 26
TOEPASSING: METHODE QSORT UIT STDLIB.H ............................................................................................. 26
C-STRINGS ......................................................................................................................................... 26
INLEZEN VAN C-STRING M.B.V SCANF ....................................................................................................... 27
INLEZEN VAN EEN C-STRING M.B.V. (F)GETS (UIT <STDIO.H>.......................................................................... 28
INGEBOUWDE STRINGFUNCTIES (<STRING.H).............................................................................................. 28
ARGC EN ARGV .................................................................................................................................... 30


HOOFDSTUK 3: STRUCTS & DYNAMISCH GEHEUGENBEHEER .......................................................... 31


STRUCTS ............................................................................................................................................ 31
WAT IS EEN STRUCT? ............................................................................................................................ 31
DEFINITIE VAN EEN STRUCT .................................................................................................................... 31
DECLARATIE VAN STRUCT-VARIABELEN ...................................................................................................... 31
BEWERKINGEN OP STRUCTS .................................................................................................................... 32
POINTER NAAR STRUCT.......................................................................................................................... 33
STRUCTS EN FUNCTIES ........................................................................................................................... 33
DYNAMISCH GEHEUGENBEHEER .............................................................................................................. 34
PROBLEEMSITUATIE .............................................................................................................................. 35
METHODES DYNAMISCH GEHEUGENBEHEER ............................................................................................... 36
VEELGEMAAKTE FOUTEN EN PROBLEMEN .................................................................................................. 38


HOOFDSTUK 4: GELINKTE LIJSTEN ................................................................................................... 39


GELINKTE LIJSTEN: ALGEMEEN ................................................................................................................ 39
DE ARRAY: VOORDELEN ......................................................................................................................... 39


2

,DE ARRAY: NADELEN ............................................................................................................................. 39
GELINKTE LIJST: PRINCIPE ....................................................................................................................... 39
ENKELGELINKTE LIJST ............................................................................................................................ 39
DUBBELGELINKTE LIJST .......................................................................................................................... 40
DEFINITIE EN DECLARATIE VAN EEN GELINKTE LIJST ..................................................................................... 40
EEN GELINKTE LIJST OVERLOPEN.............................................................................................................. 40
EEN GELINKTE LIJST OPBOUWEN ............................................................................................................. 41
ACHTERAAN TOEVOEGEN ....................................................................................................................... 41
VOORAAN TOEVOEGEN ......................................................................................................................... 42
TUSSENIN TOEVOEGEN .......................................................................................................................... 43
EEN GELINKTE LIJST VERNIETIGEN ............................................................................................................ 45
VOORDELEN/NADELEN GELINKTE LIJST ..................................................................................................... 47


HOOFDSTUK 5: BIT MANIPULATION ............................................................................................... 48




3

,HOOFDSTUK 1 – BASISCONCEPTEN IN C

SITUERING PROGRAMMEERTAAL C

• C staat zeer dicht bij hardware, haalt daaruit zijn snelheid
• Toepassingen: Unix, Windows, aansturing hardware, tijdkritische applicaties
• Historiek: ANSI C (1972 = oudste), C99 (1999), C11 (2011)


EERSTE C-PROGRAMMA


COMMENTAAR

• Genegeerd door compiler
• Meerdere regels
/* ….
….
*/
• 1 regel (sinds C99)
//…



RETURN 0

• Einde van een succesvol programma
• Return andere waarde à probleem in het programma
• Opvragen exit status: echo %ErrorLevel%




PROCUDURELE TAAL

• C is een procedurele taal: procedures staan centraal
• « Objectgeoriënteerde taal: objecten staan centraal




4

,PROGRAMMASTRUCTUUR

/********************************************
Naam bestand – korte zin over de inhoud
************************************************/
#include <studio.h> // Preprocessing directives
[declaraties variabelen/constanten]
[declaraties functies (a)]
[definities functies (b)]
int main() {

}

[definities functies (a)]

PREPROCESSING DIRECTIVES

• Instructies beginnend met symbool #
• Instructies bestemd voor de compiler
• Compiler voert deze instructies uit alvorens de code te compileren
• Staan meestal aan het begin van het programma (mogen ook ergens anders staan)

#include <stdio.h>
#define PI 3.14159


VARIABELEN EN FUNDAMENTELE DATATYPES


VARIABELEN DECLAREREN

• Elke variabele moet vooraf worden gecontroleerd
o ANSI C: declaraties variabelen vòòr alle andere opdrachten

int a, b, c;

• Naam van de variabele
o Bevat willekeurig aantal lettes, underscores of cijfers
o Begint met een letter of underscore (geen cijfer)
o Stijl
§ Gebruik geen hoofdletters
§ Woordseparatie via underscore
§ Gebruik zinvolle namen
§ Naamlengte typisch tussen 5-15 karakters




5

,FUNDAMENTELE DATATYPES IN C

• Alle fundamentele datatypes zijn numeriek (ook char)
• Kunnen opgesplitst worden
o Gehele types
o Reële types: float, double, long double
• Lengte van het type (bereik) is machine-afhankelijk
o Operator sizeof geeft lengte in bytes van type of uitdrukking
o Syntax

sizeof(type) sizeof(uitdrukking)
è sizeof(float) ≤ sizeof (double) ≤ sizeof (long double)




GEHELE TYPES

• 2 soorten: signed en unsigned
o Met/zonder teken à ander bereik!
o Default signed, met uitzondering van char
o Afhankelijk van de compiler is char: signed char of unsigned char

• Overzicht signed gehele types:


Type Synoniemen

Signed char

Short Short int, signed short, signed short int

Int Signed, signed inta

Long Long int, signed long, signed long int

Long long int, signed long long, signed long long
Long long (C99) int

• Overzicht unsigned gehele types:


Type Synoniemen

Bool (defined in stdbool.h)

à in stdbool.h: ook true of false
Bool (C99) (zonder: 0 en 1)

Afhankelijk van de compiler: char synoniem
Unsigned char met signed char of unsigned char

Unsigned short Unsigned short int


6

, Unsigned int Unsigned

Unsigned long Unsigned long int

Unsigned long long (C99) Unsigned long long int




LITERALS

• Gehele getallen
o {prefix}opt {+|-}opt getal{suffix}opt
o prefix:
decimaal: octaal: 0 hexadecimaal: 0x|0X
o suffix:
int unsigned: u|U
long: l|L unsigned long: ul|UL
long long: ll|LL unsigned long long: ull|ULL

int i = 0x200; unsigned int ui = 512U;
unsigned long ul = 0xf0FUL;
long long ll = 0777ll

• Reële getallen
o {+|-}opt getal.getal{{e|E}{+|-}opt {suffix}opt
o suffix:
double: float: f|F long doube: l|L

float f = 123.456F;
long double ld = 987E-7l


• Karakters: tussen enkele aanhalingstekens

‘a’ ‘?’ ‘\n’ ‘\t’ ‘\”’ ‘\\’

• Strings: tussen dubbele aanhalingstekens

“dit is tekst”

Opmerking: ‘a’ ≠ “a”




7

, CONSTANTEN

• ANSI C:

#define NAAM waarde
#define PI 3.14159

• C99

const type NAAM = waarde;
const double PI = 3.14159;



IMPLICIETE CONVERSIES

• Bij toekenningsopdrachten
o Impliciete (= automatische) conversies in C
o Eventueel warning voor toekenningsopdrachten die informatie kunnen verliezen
(van wider naar narrower type)

float x = 2.8 à double naar float
int i = x; à float naar int


• Bij rekenkundige opdrachten
o Treden op bij binaire operatoren waarbij operandi van ≠ type zijn
o Widening van narrower type naar wider type

x += 2.5 à float naar double, double naar float



EXPLICIETE CONVERSIES – CASTEN

• Expliciet forceren van conversie

double d = 13.7;
int i = (int) d; // i krijgt waarde 13
double d = (double) i / 3;


• Gebruik casts om aan te geven wat de bedoeling is à niet steunen op impliciete conversie

CONVERSIES.C




8

The benefits of buying summaries with Stuvia:

Guaranteed quality through customer reviews

Guaranteed quality through customer reviews

Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.

Quick and easy check-out

Quick and easy check-out

You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.

Focus on what matters

Focus on what matters

Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!

Frequently asked questions

What do I get when I buy this document?

You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.

Satisfaction guarantee: how does it work?

Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.

Who am I buying these notes from?

Stuvia is a marketplace, so you are not buying this document from us, but from seller stephaniepicard. Stuvia facilitates payment to the seller.

Will I be stuck with a subscription?

No, you only buy these notes for $4.31. You're not tied to anything after your purchase.

Can Stuvia be trusted?

4.6 stars on Google & Trustpilot (+1000 reviews)

66579 documents were sold in the last 30 days

Founded in 2010, the go-to place to buy study notes for 14 years now

Start selling
$4.31  1x  sold
  • (0)
  Add to cart