hello everyone,
I'm learning objective-c at the moment and am having a little bit of trouble. I think I'm grasping it a little but am confused because of two examples. The first has the pointer on the left side. The second example has the pointer on the right side. Does having * on either side make a difference, or does it mean somthing else when on each side respectively? Is it on the right side when used with types and left side when used on identifyers? By the way, the book I'm using is "Objective-c for Dummies." I wasn't sure if it was a typo, but after looking on the internet I've seen the * used on both sides. Thanks in advance.
Example 1:
int anInterger = 42;
int *anIntergerPointer = &anInterger;
Example 2:
typedef struct {
float exchangeRate;
double budget;
double exchangeTransaction;
} budget;
budget vacationBudgetEurope;
budget vacationBudgetEngland;
void spendDollars(budget* theBudget, double dollars);
void chargeForeignCurrency(budget* theBudget, double foreignCurrency);
int main (int argc, const char * argv[]) {
vacationBudgetEurope.exchangeRate = 1.2500;
vacationBudgetEurope.budget = 1000.00;
double numberDollarsInEuroland = 100;
double numberEuros = 100;
vacationBudgetEngland.exchangeRate = 1.5000;
vacationBudgetEngland.budget = 2000.00;
double numberDollarsInPoundland = 100;
double numberPounds = 100;
spendDollars(&vacationBudgetEurope, numberDollarsInEuroland);
chargeForeignCurrency(&vacationBudgetEurope, numberEuros);
spendDollars(&vacationBudgetEngland, numberDollarsInPoundland);
chargeForeignCurrency(&vacationBudgetEngland, numberPounds);
return 0;
void spendDollars(budget* theBudget, double dollars) {
theBudget->budget -= dollars;
}
void chargeForeignCurrency(budget* theBudget, double foreignCurrency) {
theBudget->exchangeTransaction = foreignCurrency*theBudget->exchangeRate;
theBudget->budget -= theBudget->exchangeTransaction;
}
Thanks again,
Cyatic
I'm learning objective-c at the moment and am having a little bit of trouble. I think I'm grasping it a little but am confused because of two examples. The first has the pointer on the left side. The second example has the pointer on the right side. Does having * on either side make a difference, or does it mean somthing else when on each side respectively? Is it on the right side when used with types and left side when used on identifyers? By the way, the book I'm using is "Objective-c for Dummies." I wasn't sure if it was a typo, but after looking on the internet I've seen the * used on both sides. Thanks in advance.
Example 1:
int anInterger = 42;
int *anIntergerPointer = &anInterger;
Example 2:
typedef struct {
float exchangeRate;
double budget;
double exchangeTransaction;
} budget;
budget vacationBudgetEurope;
budget vacationBudgetEngland;
void spendDollars(budget* theBudget, double dollars);
void chargeForeignCurrency(budget* theBudget, double foreignCurrency);
int main (int argc, const char * argv[]) {
vacationBudgetEurope.exchangeRate = 1.2500;
vacationBudgetEurope.budget = 1000.00;
double numberDollarsInEuroland = 100;
double numberEuros = 100;
vacationBudgetEngland.exchangeRate = 1.5000;
vacationBudgetEngland.budget = 2000.00;
double numberDollarsInPoundland = 100;
double numberPounds = 100;
spendDollars(&vacationBudgetEurope, numberDollarsInEuroland);
chargeForeignCurrency(&vacationBudgetEurope, numberEuros);
spendDollars(&vacationBudgetEngland, numberDollarsInPoundland);
chargeForeignCurrency(&vacationBudgetEngland, numberPounds);
return 0;
void spendDollars(budget* theBudget, double dollars) {
theBudget->budget -= dollars;
}
void chargeForeignCurrency(budget* theBudget, double foreignCurrency) {
theBudget->exchangeTransaction = foreignCurrency*theBudget->exchangeRate;
theBudget->budget -= theBudget->exchangeTransaction;
}
Thanks again,
Cyatic