CISC105 - General Computer Science
Homework #4
Pointers and Operations on Bits
1. (5) What is the address operator?
2. (5) What is the indirection operator?
3. (5) What is the value of x?
int counter = 25;
int *a_pointer;
a_pointer = &counter;
x = *a_pointer;
4. (5) Using a pointer, set the month of today's date to 12.
struct date
{
int month;
int day;
int year;
};
struct date todays_date;
struct date *p1;
p1 = &todays_date;
5. (5) Code the C statements to link the following lists together.
struct item
{
int value;
struct item *next;
};
struct item list1, list2, list3;
6. (5) Code the C statements to link 'list2a' in between 'list2' and 'list3'
(use code from Problem #5).
struct item list2a;
7. (5) Code the C statement that marks 'list3' as the end of the linked list
(use code from Problem #5).
8. (5) Using the following code, set x equal to the fourth element of the array
values (use a pointer).
int x, values[], *values_pointer;
values_pointer = values;
9. (5) Using the following code, what is the value of x?
static char string1[] = "This is a character string";
char c, x, *c_pointer;
c_pointer = string1;
x = *(c_pointer);
10. (5) Using the code from Problem #9, what are the values of a and b?
char a, b;
c_pointer = &string1[12];
a = *(c_pointer++);
b = *(--c_pointer);
11. (5) Given the following function, declare a pointer to a function that returns
an int and assign the function to it.
int lookup ();
12. (5) Convert -25 (decimal) to binary using two's compliment (use an 8 bit word).
13. (5) Perform the following bitwise operation.
w1 0 1 0 0 1 1 1 0
w2 1 1 0 1 0 1 0 1
w1 & w2
14. (5) Perform the following bitwise operation.
w1 0 1 0 0 1 1 1 0
w2 1 1 0 1 0 1 0 1
w1 | w2
15. (5) Perform the following bitwise operation.
w1 0 1 0 0 1 1 1 0
w2 1 1 0 1 0 1 0 1
w1 ^ w2
16. (5) Perform the following bitwise operation.
w1 0 1 0 0 1 1 1 0
~w1
17. (5) Perform the following bitwise operation.
w1 0 1 0 0 1 1 1 0
w1 << 3
18. (5) Perform the following bitwise operation.
w1 0 1 0 0 1 1 1 0
w1 >> 2
19. (5) Perform the following bitwise operation.
w1 1 0 0 1 1 1
w2 0 1 0 1 1 0 0 1
w1 & w2
20. (5) Define a structure of packed data where the first two bits are flags, the next
two bits are a type field, and the remaining four bits are an address field.