Lecture2

Lecture2 - 211: Computer Architecture Fall 2011 Abhishek...

Info iconThis preview shows pages 1–11. Sign up to view the full content.

View Full Document Right Arrow Icon
Abhishek Bhattacharjee Topic: s C Programming 211: Computer Architecture Fall 2011
Background image of page 1

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

View Full DocumentRight Arrow Icon
Rutgers University Abhishek Bhattacharjee 2 Introduction to C TAs will cover C in more details in sections s Will also help you with machine/compilation logistics Learning C s Is no big deal; you already know Java s Start by coding and testing small programs s Learn how to use a debugger! c TAs will help
Background image of page 2
Rutgers University Abhishek Bhattacharjee 3 Why Learn C? You are learning to be a computer scientist s Languages are just tools s Choose tool appropriate to the task Current task: learning computer architecture and how programs written in high-level language runs on computers s C closer to machine so easier to see mapping It’s fun
Background image of page 3

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

View Full DocumentRight Arrow Icon
Rutgers University Abhishek Bhattacharjee 4 Comparison with Java Java Program Byte Code (.class) Java Virtual Machine Hardware and Operating System javac … java … C Program Compiled Code gcc …
Background image of page 4
Rutgers University Abhishek Bhattacharjee 5 Anatomy of a C Program #include <stdio.h> #include <stdlib.h> char cMessage[] = "Hello\n"; /* Execution will start here */ int main (int argc, char **argv) { int i, count; count = atoi(argv[1]); for (i = 0; i < count; i++) { printf("Hello %d\n", i); } } include files declaration of global variables one or more function; each program starts execution at “main” declaration of local variables code implementing function comment
Background image of page 5

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

View Full DocumentRight Arrow Icon
Rutgers University Abhishek Bhattacharjee 6 Comments Begins with /* and ends with */ Can span multiple lines. Cannot have a comment within a comment s Example: “my/*don't print this*/string” s would be printed as: my/*don't print this*/string Comments are critical s How much and where is an art
Background image of page 6
Rutgers University Abhishek Bhattacharjee 7 Variable Declarations Variables are used as names for data items Each variable has a type , which tells the compiler how the data is to be interpreted (and how much space it needs, etc.) int counter; int startPoint; Variables can be global or local global: declare outside scope of any function accessible from anywhere local: declare inside scope of a function accessible only from inside of the function
Background image of page 7

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

View Full DocumentRight Arrow Icon
Rutgers University Abhishek Bhattacharjee 8 Basic Data Types Modifiers s short, long : control size/range of numbers s signed, unsigned : include negative numbers or not Keyword Data Type Examples char individual characters ‘a’, ‘b’, ‘\t’, ‘\n’ int integers -15, 0, 35 float real numbers -23.6, 0, 4.56 double real numbers with double precisions -23.6, 0, 4.56
Background image of page 8
Rutgers University Abhishek Bhattacharjee 9 Arithmetic Operators Symbol Operation Usage Assoc * multiply x * y l-to-r / divide x / y l-to-r % modulo x % y l-to-r + addition x + y l-to-r - subtraction x - y l-to-r * / % have higher precedence than + - Rule of thumb: remember only a few precedence rules Use () for everything else
Background image of page 9

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

View Full DocumentRight Arrow Icon
Rutgers University Abhishek Bhattacharjee 10 Special Operators: ++ and -- Changes value of variable before (or after) its value is used in an
Background image of page 10
Image of page 11
This is the end of the preview. Sign up to access the rest of the document.

This document was uploaded on 10/31/2011 for the course 198 211 at Rutgers.

Page1 / 37

Lecture2 - 211: Computer Architecture Fall 2011 Abhishek...

This preview shows document pages 1 - 11. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online