lec1_intro_c

lec1_intro_c - C Intro Marco Gruteser 331 Computer...

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

View Full Document Right Arrow Icon
Some slides adapted from Bryant, O’Hallaron, and Nath. 1 C Intro Marco Gruteser 331 Computer Architecture and Assembly Language
Background image of page 1

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

View Full DocumentRight Arrow Icon
hello, world 2
Background image of page 2
3 main Function n Every C program must have a function called main() . n This is the code that is executed when the program is run. n The code for the function lives within brackets: n main() n { n /* code goes here */ n }
Background image of page 3

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

View Full DocumentRight Arrow Icon
4 Arithmetic Operators n Symbol Operation Usage n * multiply x * y n / divide x / y n % modulo x % y n + addition x + y n - subtraction x - y n All associate left to right. n * / % have higher precedence than + - .
Background image of page 4
5 Special Operators: ++ and -- n Changes value of variable before (or after) its value is used in an expression. n Symbol Operation Usage n ++ postincrement x++ n -- postdecrement x-- n ++ preincrement ++x n <= predecrement --x n Pre : Increment/decrement variable before using its value. n Post : Increment/decrement variable after using its value.
Background image of page 5

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

View Full DocumentRight Arrow Icon
6 Examples n #include <stdio.h> #include <stdlib.h> int main() { char weight[4]; int w; w=140; printf ("Here is what you weigh now: % i\n",w); w--; printf("w--: %i\n",w); w++; printf( l ++w: %i\n",w); printf ( l pre DECR %i \n z , --w); printf ( l post INCR %i \n z , w+ +); printf ( l value of w %i \n z , w); return(0); } #include<stdio.h> main( ) { int i = 3, j = 4,k; k = i++ + --j; printf("i = %d, j = %d, k = %d",i,j,k); }
Background image of page 6
7 Relational Operators n Symbol Operation Usage n > greater than x > y n >= greater than or equal x >= y n < less than x < y n <= less than or equal x <= y n == equal x == y n != not equal x != y n Result is 1 (TRUE) or 0 (FALSE). n Note : Don't confuse equality (==) with assignment (=).
Background image of page 7

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

View Full DocumentRight Arrow Icon
8 Logic Operators n Symbol Operation Usage n ! logical NOT !x n logical AND n || logical OR x || y n Treats entire variable (or value) as TRUE (non-zero) or FALSE (zero). n Result is 1 (TRUE) or 0 (FALSE).
Background image of page 8
9 Variable Declarations n Variables are used as names for data items. n Each variable has a type , which tells the compiler how the data is to be interpreted (and how much space it needs, etc.). n
Background image of page 9

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

View Full DocumentRight Arrow Icon
Image of page 10
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 30

lec1_intro_c - C Intro Marco Gruteser 331 Computer...

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

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