DEREFERENCE
this operator (aka indirection) is used to access the data pointed to by the address.
dataType variableName = *pVariableName;
USAGE:
#include <stdio.h>
#include <stdbool.h>
int main(int argc, char* argv[])
{
int integerVariable = 100;
double doubleVariable = 2.71828;
int* pIntegerVariable = &integerVariable;
double* pDoubleVariable = &doubleVariable;
int anotherIntegerVariable = *pIntegerVariable; //anotherIntegerVariable == integerVariable
double anotherDoubleVariable = *pDoubleVariable; //anotherDoubleVariable == doubleVariable
bool bAreIntegersEqual = (anotherIntegerVariable == integerVariable);
bool bAreDoublesEqual = (anotherDoubleVariable == doubleVariable);
printf("variable values integerVariable and anotherIntegerVariable are %s\n", bAreIntegersEqual ? "equal" : "not equal");
printf("variable values doubleVariable and anotherDoubleVariable are %s\n", bAreDoublesEqual ? "equal" : "not equal");
return 0;
}
* the address-of operator obtains the address while the dereference operator obtains
the data at an address
* OUTPUT:
variable values int1 and another_int1 are equal
variable values doub1 and another_doub1 are equal
Last updated