Example Questions

Here are some example questions you should do as preparation for the final! Check here for the solutions.

How to write C-code

In this term, you have spent some considerable amount of time writing C code, struggeling with pointers and fighting against segmentation faults. I saw many nicely written programs, and tried to improve less nicely written code...

However, none of you has produced examples like this. Enjoy!

The International Obfuscated C Code Contest

This contest is held more or less frequently since the eighties. Here are some winning one liners:

David Korn, AT&T Bell Labs (1987): Un*x

David Korn is also known for writing the Korn Shell, a popular unix shell. Here are some hints to understand the example below.
  main() { printf(&unix["\021%six\012\0"],(unix)["have"]+"fun"-0x60);}

Mark Schnitzius (1995): Factoring Nubmers

... where a segmentation fault is a feature, not a bug. Run the program with a command line argument, e.g. ./a.out 24
main(l,i,I)char**i;{l/=!(l>(I=atoi(*++i))||fork()&&main(l+1,i-1)||I%l);return printf("%d\n",l);}

Academic Programming

Ken Perlin, academy award winning computer graphics professor at NYU - has the following example on his homepage:
  main(){char *b=" .:-;!/>)|&IH%*#";float i,j,k,r,x,y=-16;while

How not to write Code

This might not be very comforting, but it's good to know that computer bugs are everywhere. The Association for computing machinery (ACM) maintains a forum on Risks to the Public in Computers and Related Systems.

Also, someone took the efforts to post a list of the top 10 computer bugs. Hopefully, you'll never make it into these charts.