Given the following function signature, write C code to set the memory location passed in (say, for an embedded system).
#include <stdlib.h>
#include <stdio.h>
void setMemoryLocation(int memoryLocation, int value)
{
*((int*)memoryLocation) = value;
}
int main()
{
int *pointer = malloc(sizeof(int));
setMemoryLocation((int)pointer, 12345);
printf("%d\n", *pointer);
return 0;
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment