|
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Problems
Problem 1.1:
Why can't you dereference a void pointer?
[Solution]
Problem 1.2:
Given the function:
void print_bit_int(int value);
which takes an integer as a parameter and prints out its bit representation,
write a line of code which prints out the bit representation for a float
spark (you can assume that a float is the same size as an integer).
[Solution]
Problem 1.3:
Write a function, memcmp(), which takes two void pointers and a length
in bytes, and compares the memory at those two locations for that many
bytes. It should return a non-zero value if the memory matches, and zero
if the memory does not match.
[Solution]
Problem 1.4:
What is wrong with the following code? How would you fix it with a cast?
int main()
{
int steve;
int *spark;
void *notes;
steve = 500;
spark = &steve;
notes = (void*)spark;
*notes = 600;
printf("%d\n", steve);
return 0;
}
[Solution]Problem 1.5:
What is wrong with the following code?
int main()
{
int a, b;
double d, e
void* v[10];
v[0] = &a;
v[1] = &d;
v[2] = &b;
v[3] = &e;
int x = *((int*)v[0]);
double w = *((double*)v[1]);
int y = *((int*)v[1]);
return 0;
}
[Solution] |
|
|||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||
|
Contact Us | Privacy Policy | Terms and Conditions | About
©2006 SparkNotes LLC, All Rights Reserved.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||