{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

C_lecture_1 - CS 11 C track lecture 1 Administrivia Need a...

Info icon This preview shows pages 1–13. Sign up to view the full content.

View Full Document Right Arrow Icon
CS 11 C track: lecture 1 Administrivia Need a CS cluster account http://www.cs.caltech.edu/ cgi-bin/sysadmin/account_request.cgi Need to know UNIX ITS tutorial linked from track home page Track home page: www.cs.caltech.edu/courses/cs11/material/c/mike
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Assignments 1st assignment is posted now Due one week after class, midnight Late penalty: 1 mark/day Redos
Image of page 2
Main textbook C: A Software Engineering Approach, 3rd ed. by Peter A. Darnell, Philip E. Margolis Thorough, readable
Image of page 3

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Supplemental textbook Kernighan and Ritchie: The C Programming Language, 2nd. ed. 1st edition NOT acceptable "ANSI C" Good for reference
Image of page 4
C: pros and cons What C is good at low-level programming speed and memory efficiency portability (sorta) Bad things about C unsafe!!! low level of abstraction
Image of page 5

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Getting started (1) The "hello, world!" program: #include <stdio.h> int main(void) { printf("hello, world!\n"); return 0; }
Image of page 6
Getting started (2) Make this into a file called hello.c using a text editor e.g. emacs , vi , nedit , pico Compile into a program and run: % gcc hello.c -o hello % hello hello, world! % Woo hoo!
Image of page 7

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Source code to executable (1) What you write is called "source code" Two kinds of source code files: regular code (files end in " .c ") header files (files end in " .h ") Compiler turns source code into "object code" (files end in " .o ") Linker turns object code file(s) into executable (no special file suffix)
Image of page 8
Source code to executable (2) The program gcc is both a compiler and a linker When you do this: % gcc hello.c -o hello Then gcc compiles hello.c to hello.o links hello.o with system libraries outputs the binary executable hello removes hello.o
Image of page 9

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Source code to executable (3) You can do each step individually: % gcc -c hello.c (compile only) % gcc hello.o -o hello (link only) In this case, hello.o is not removed Sequence: compiling : source code to object code linking : object code to binary executable
Image of page 10
The C language - overview Programs are built up of functions Functions take in arguments compute something return a result The main() function is where program execution starts
Image of page 11

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Data types (1) All data in C has to have a specified type Examples: int (integer) char (character) float or double (approximate real number) others Variables hold data of a particular type only Variables must be declared before use
Image of page 12
Image of page 13
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern