Class Notes (837,689)
Canada (510,396)
CSC209H1 (41)
Karen Reid (20)


1 Page
Unlock Document

Computer Science
Karen Reid

C PROGRAMMING LANGUAGE  The C Programming Language  About C o C is a high-level language — structured o Similar to Java – Java copied the best of C o C is a low-level language — machine access o #include – use declarations of functions o C is a small language, extendable with libraries o first line are librarys included o C is permissive: assumes you know what you’re doing  stdio.h has printf o Positives: efficient, powerful, portable, flexible o each c program has a main function o Bad: easy to make errors, obfuscation, little support for modul returns an int = 0 if no errors, else errors  Obfuscated = render obscure, unclear or unintelligible o have to declare variables & types  See sds.c  completely illegible, still compiles  statically type language  Ex. avgs.c o Functions must be 1. #include  Declared – tells compiler how to use function 2. #include  Defined – creates the item 3. o Declarations must appeare before code 4. int main(int argc, char *argv[]) { o Uninitialized variables have no default value 5. char **p; o No run-time checking 6. FILE *fp, *fpout; o No polymorphism 7. int total, nums, num; 8.  printf format strings 9. if (argc < 2) { o no objects 10. fprintf (stderr, "Usage: %s file...\n",  To compile c on UNIX based machine o gcc –Wall -g -o [cprogramname] [cprogramname].c 11. argv[0]); 12. exit (1);  Basic Controll Structures 13. } o for loop – like java 14.  body is one statement 15. fpout = fopen("avgs.txt", "w");  braces { } enclose blocks 16. 17. if (!fpout) {  blocks introduce scrope level  can’t mix declarations and non-declarations 18. fprintf(stderr,  for (int I … is illegal in ANSI C 19. "Error: can’t open output file\n");  fprintf can print to a file, printf prints to standard output 20. exit(1); 21. }  Ex. gcd.c 22. 1. #include 23. p = argv; 2. 24. while (*++p) {
More Less

Related notes for CSC209H1

Log In


Join OneClass

Access over 10 million pages of study
documents for 1.3 million courses.

Sign up

Join to view


By registering, I agree to the Terms and Privacy Policies
Already have an account?
Just a few more details

So we can recommend you notes for your school.

Reset Password

Please enter below the email address you registered with and we will send you a link to reset your password.

Add your courses

Get notes from the top students in your class.