CS349/SE382 A1 C Programming TutorialCS349/SE382 A1 C Programming TutorialErin LesterJanuary 2005CS349/SE382 A1 C Programming TutorialOutlineDi erences from C++CommentsVariable DeclarationsObjectsDynamic MemoryBoolean Typestructs, enums and unionsOther DierencesThe Event LoopCS349/SE382 A1 C Programming TutorialDierences from C++CommentsComments:I C has no one-line comments, only block comments/* this comment is valid in C *//* so isthis one */// but this one is noti = 2; // and neither is this oneCS349/SE382 A1 C Programming TutorialDierences from C++Variable DeclarationsVariable Declarations:I Variables must be declared at the beginning of code blocks,before any other types of statements#include void main(){char c;int i;i = 10 + 2;char *mystring = "Hello World"; /* not allowed */c = ’\n’;printf("%s%c", mystring, c);}CS349/SE382 A1 C Programming TutorialDierences from C++ObjectsObjects:I C has no objectsI use ADTs — remember cs246 — to be modularCS349/SE382 A1 C Programming TutorialDierences from C++ObjectsCreating a mock class/ADTStep 1. Create a header le for your mock classinclude:I empty structure declarationI function headers w/ structure as parameterCS349/SE382 A1 C Programming TutorialDierences from C++ObjectsCreating a mock class/ADTStep 2. Implement the code for the mock classin a ‘.c’ le:I include your ‘.h’ leI declare the structureI implement the ADT’s functionsCS349/SE382 A1 C ...
I memory is freed using ‘free()’ I free() takes the address of a non-null variable as its parameter I there is no garbage collection, so don’t forget to clean-up what you create
CS349/SE382 A1 C Programming Tutorial Differences from C++ Boolean Type