Presentation is loading. Please wait.

Presentation is loading. Please wait.

Final Review Yuan Long CSC3320. Variables byte,char,int,long float,double.

Similar presentations


Presentation on theme: "Final Review Yuan Long CSC3320. Variables byte,char,int,long float,double."— Presentation transcript:

1 Final Review Yuan Long CSC3320

2 Variables byte,char,int,long float,double

3 Variables Type conversion: Narrower type can be converted to wider type. Wider type can be converted to narrower(Cast). long double double float Unsigned long int long int unsigned int int float f, frac_part; frac_part = f – (int) f; short int i; int j = 1000; i = j * j; /* WRONG */

4 Variables struct struct sample{ int a; char b; }; sample test1,*q; test1.a=1; (*q).a=2; q->b=‘3’;

5 Arrays Declaration for an array is different from java. One dimensional: int a[3]; int a[3]={0}; int a[3]={1,2}; int a[3]={1,2,3}; Int a[]={1,2,3}; Two dimensional: int a[2][2]={{1,2},{3,4}};

6 String Character array(String in java) ‘\0’ means the end of a string char data1[8] = “June 14”; //strlen(data1)=7 char data2[9] = “June 14”; //strlen(data2)=7 char data3[7] = “June 14”; //strlen(data3)? Error char data4[ ] = “June 14”; //strlen(data4)=7 June14\0 June14 June14 char *data5 = “June 14”; //strlen(data5)=7

7 String printf(“%s”, str); scanf(“%s”,str); // read until ‘\n’ found

8 Pointer Declaration and initialization: int i,j; int *p=&i,*q=&i; Assign value : p=&j; *p=j; *(&j) equals j

9 Example 1 of pointer int i, j, *p, *q; p = &i; q = p; p q i

10 Example 2 of pointer int i, j, *p, *q; p = &i; q = &j; *q = *p; p q i

11 Pointer and Array Use a pointer to represent an array int a[5]; char b[5]; int *pa=a; or int *pa=&a[0] char *pb=b; or char *pb=&b[0] Use a pointer to access the element in array p = &a[2]; q = p + 3; p += 4;

12 Pointer Use pointer as an argument. Be careful: the original value may be changed. Refer to swap example. Refer to array example. Use pointer as a return value. Avoid returning a local pointer(defined in a function).

13 Functions Declare your functions before you use them Two ways: (1)The whole definition is placed before you use them. (2)Just declare it before you use them(prototype). double average(double x, double y); double average(double, double); int main() { // use average} double average(double x, double y) { ……….}

14 Functions Parameters(appear in function definition) Arguments(appear in function call) Recursive function

15 Library Functions How to use printf()? How to use scanf()? e.g. scanf(“%d,%d”,&x,&y); Useful functions in math.h Useful functions in string.h

16 System calls File management open() close() read() write() lseek()

17 System calls Process management fork() wait() getuid() exec()

18 Process Init() process How to duplicate a process? Zombie process? Orphan process? How to get rid of zombie process?  wait()

19 Final Exam Multiple choice (Only one answer) Short answers Filling the blanks for short program Writing the output for a program Write a program


Download ppt "Final Review Yuan Long CSC3320. Variables byte,char,int,long float,double."

Similar presentations


Ads by Google