Week 1: Course introduction
Lecture notes
In-class exercises
- Create a file called
hello.c
on the remote server. We'll write a small "Hello, world!" program, and compile and run it.
- Do
ls /usr/share/cs644/code
on the remote server to see the course's source code.
- Notice that each of you has a directory under
/home/shared
. (Try running ls /home/shared
with --color=never
if you can't read the output.) Pick one of your classmates and create a file with a greeting in it.
- Linux commands and C library functions are documented in man pages. We'll take a look at
man ls
and man strchr
.
- A brief run-down of some useful tools:
bat
, rg
, fd
, fzf
, tldr
Homework exercises
- (★) What is the
size_t
type for in C?
- (★) True or false: Semicolons are optional in C.
- (★★) Start thinking about what language you want to use for the final project, and whether you want to follow the main track or work on your own project. (See syllabus for details.)
- (★★) Does this program have a bug? Why or why not?
- (★★) Take a look at this C function from the Python source code. Try to understand what it does and how it works. (Bonus: Can you explain how the second function in the file works?)
- (★★) Write a C program,
redact.c
, that takes a string argument and prints out the string with all digits replaced by the character 'X'. (Hint: Some standard library functions might come in handy.)
- (★★★) Research the concept of the stack and the heap for memory allocation. (Not to be confused with the data structures of the same name.) When do you use one versus the other? How do I know if a value in a C program is allocated on the stack or the heap?
- (★★★) What is the memory representation of strings (
char*
) in C? What is an alternate representation? What are the advantages and disadvantages of each?