CIS 15/615     Advanced c                                          INSTRUCTOR: RAVE HARPAZ

SUMMER 2001             

 

 

Pointers, arrays, structures and passing them to functions

 

 

1.     Evaluate the following expressions:

 

int a[]={10,20,30,40,50};

int *b=&a[1];

 

(Assume &a[0]=2000  and that your computer has 4 byte int’s!)

 

·        *(b+3)

 

·        &b[2]

 

·        b++

 

·        a+1

 

·        *b++

 

·        *(a+1)-*b

 

·        b-a

 

·        sizeof(a[3])

 

 

2.     esign and declare a struct type named clock containing: hour,min and sec fields-i.e, it should contain three int type fields.

 

Use typedef to name your data type as Time.

 

Declare a variable of the type you have declared above, named NYT and initialize it to 00:00:00 (i.e. hour=0,min=0,sec=0).

 

Declare an array containing 5 elements of type Time, the array will be named Times.

 

Wirte a function that is passed NYT and Times (i.e. a variable and an array).

 

The function should set NYT to 15:30:00 and Times to 5 different times differing by –1 hour from each other- i.e., the 1st element in the Times array should reflect the time 14:30:00,the 2nd element 13:30:00, ...

 

Note that all the changes you make to NYT and TIMES inside the function should also exist outside the function i.e. you will have to use pass pointers.

 

Use pointer notation only.