Qualcomm Interview Question
Software Engineer / Developersreinterpret_cast answer was a TOTAL BULL SHIT !!
The answer before was even more DUMBEST!!! BOTH THOSE TWO GUYS MUST BE SHOT TO DEATH, OR, their rib bones must be ripped off and shoved in their respective fucking eyeballs!!! How dare they be stupid here?
void pointtoother(void** d)
{
char* s = (char*)malloc(sizeof(char));
*d = s;
}
char* p = "all_answers_are_dumb_ass_here";//p points to an unnamed array
pointtoother( &p );
//when the call returns, p will be pointing to somewhere else
are you guys both insane?!
you guys should be shot first.. and stop using such language. you need to get some help bro.. jeez!
both the above answers are right.. try it out first before u start flaming others..
kk,
The question asks for a function which does it. I guess it is assumed that the pointer which much point to another is passed in, something like:
point_to_other(void ** ptr_to_ptr)...
void PointerToOtherObject(void** pointer, void* otherObject); // Function prototype perhaps not needed.
void PointerToOtherObject(void** pointer, void* otherObject) // Parameters are the pointer to be modified and the object that the pointer will point to after the function call.
{
*pointer = otherObject; // store the object's address within the location of pointer
}
void main(void)
{
char* stringObject = "This is a string. ";
int intObject = 256;
void* genericPointer = stringObject; // Assign the pointer to point to the string object.
PointerToOtherObject(&genericPointer, &intObject); // Call our function to change the pointer to point to the "other object", in this case, an integer.
// genericPointer now contains the intObject's address. ie, points to the int instead of the character string
}
char a = 'b';
- anonymus October 25, 2008int *p = (int*)&a;