Presentation is loading. Please wait.

Presentation is loading. Please wait.

COMS W3156: Software Engineering, Fall 2001 Lecture #20: C, continued Janak J Parekh

Similar presentations


Presentation on theme: "COMS W3156: Software Engineering, Fall 2001 Lecture #20: C, continued Janak J Parekh"— Presentation transcript:

1 COMS W3156: Software Engineering, Fall 2001 Lecture #20: C, continued Janak J Parekh janak@cs.columbia.edu

2 Next class Finish up C discussion C++

3 Today’s class Continue C Guest lecture at 6

4 C for the Java programmer Java “ripped off” C –Java widely considered “C with classes” –More like C than C++ for/while, if-then-else, switch (broken) all adopted perfectly from C Operators, ++/--, etc. Functions very similar to methods But no objects!

5 C’s data types Similar to Java’s lower-case types –char, int, short, long, single, double –no boolean – use 0 or 1 Common practice: #define TRUE 1 C is not strongly typed –int i = ‘c’; –As a matter of fact, chars are just bytes Different structures have different sizes Formal mechanism for references: pointers –Address of structure in machine’s memory!

6 Pointers (I) Can accomplish similar functionality as references in Java, but far more manual (and flexible) Basically, a class of types that “point” to an arbitrary location in memory Why? –Call-by-value vs. call-by-reference

7 Pointers (II) “&” operator: get the address of a variable “*” operator: get the value stored at an address Declaring pointers: –int *ip = null; ip is of type “int *” ip can point to something

8 Pointer examples int x = 7; int *ip = &x; printf(“%d\n”, ip); // What does this print? printf(“%d\n”, *ip); *ip = 9; printf(“%d\n”, *ip); printf(“%d\n”, x);

9 Pointers: miscellany If ip == 4, and ints are 4 bytes long, what does ip+1 equal? –This is why pointers are “typed” C does not have arrays –Basically consecutive blocks of memory pointed to int a[7]; a == &a[0]; ++a == &a[1];

10 C’s use of pointers C does not have Strings either –Basically an array of chars (char *) Basically a pointer to a block of memory Char pointers are all over the place C’s loose typing: the meaning of “0” –False –End-of-string character –Null pointer (#define NULL 0)

11 Administrativia Prototype status D-Day 1 is next Wednesday No homeworks for a while: HW4 assigned on full implementation deadline –We can adjust the end date; do people want this?


Download ppt "COMS W3156: Software Engineering, Fall 2001 Lecture #20: C, continued Janak J Parekh"

Similar presentations


Ads by Google