Recitation6_mod.pptx - CS314 Section 3 Recitation 6 Honglu...

This preview shows page 1 - 17 out of 85 pages.

CS314 – Section 3 Recitation 6 Honglu Zhou ([email protected]) 1
Image of page 1

Subscribe to view the full document.

Content C
Image of page 2
Basic things Constant: Integer constant 10 -30 0 Real constant: 3.14, -0.56, 18.0 Character constant: ‘x’, ‘X’, ‘?’, ‘9’ -- single quotes, one character string constant: “Hello!”, “K88”, “9” -- double quotation marks, one or more characters
Image of page 3

Subscribe to view the full document.

Variable: - whose value can be changed - It must be predefined before using it int a; float b; char c; a=1; b=2.5; c= ‘A’; Basic things int a, b, c; (define mutiple variables in one line) int a=0, b=0, c=0; (initialize at the same time) int a=b=c=0; (not right!!)
Image of page 4
Variable: - whose value can be changed - It must be predefined before using it int a; float b; char c; a=1; b=2.5; c= ‘A’; Naming Rules: (1) Identifier can consist of English alphabet, numbers, or underline. (2) Identifier must start with alphabet or underline. (3) Can not use Keywords (i.e. int) in C. (4) Any number of characters, the maximum length depends on the compiler. (5) Case sensitive. (i.e. sum, Sum, and SUM are different. ) Basic things
Image of page 5

Subscribe to view the full document.

Comment: // … - for one line of code /* … */ - For multiple lines of code Basic things
Image of page 6
printf() int a=1; float b=2.5; char c=‘A’; printf(“a=% d \n”, a); printf(“b=% f \n”, b); printf(“c=% c \n”, c); printf(“End of program. \n”); Basic things Output: a=1 b=2.500000 c=A End of program
Image of page 7

Subscribe to view the full document.

Data type: Basic things int int a; long long int a; / long a; short short int a; / short a; unsigned unsigned int a; unsigned long b; unsigned short c; float float a; double double a; long double long double a;
Image of page 8
Data type: Basic things char char a; enum enum response { no, yes, none }; enun response answer; array int score[10]; char name[20]; struct struct data { int year; int month; int day; }; struct data d;
Image of page 9

Subscribe to view the full document.

Data type: Basic things union union { int single; char spounseName[20]; struct data divorcedDay; } married; pointer int *ptr; char *pStr; void void Sort(int array[], int n); void *malloc(unsigned int size);
Image of page 10
sizeof() Basic things
Image of page 11

Subscribe to view the full document.

sizeof() Basic things
Image of page 12
sizeof() The output will be different in different compiler environment!!! Basic things
Image of page 13

Subscribe to view the full document.

Arithmetic Operators operator meaning example result associativity - Opposite number -1 -(-1) -1 1 Right to lef * multiplication 12*2 24 Lef to right / division 12/5 12.0/5 2 2.4 Lef to right % modulus 11%5 11%(-5) (-11)%5 1 1 -1 Lef to right + addition 5+1 6 Lef to right - subtraction 5-1 4 Lef to right
Image of page 14
Arithmetic Operators operator meaning example result associativity - Opposite number -1 -(-1) -1 1 Right to lef * multiplication 12*2 24 Lef to right / division 12/5 12.0/5 2 2.4 Lef to right % modulus 11%5 11%(-5) (-11)%5 1 1 -1 Lef to right + addition 5+1 6 Lef to right - subtraction 5-1 4 Lef to right Integer division Float division
Image of page 15

Subscribe to view the full document.

Arithmetic Operators Increment Operator (++) & Decrement Operator (--) Can be prefix or postfix. int n=3; printf(“%d \n”, n++); printf(“%d \n”, ++n);
Image of page 16
Arithmetic Operators Increment Operator (++) & Decrement Operator (--) Can be prefix or postfix.
Image of page 17
You've reached the end of this preview.
  • Fall '02
  • Staff

{[ 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