void main(){ dog cujo={"Cujo","Saint Bernard",90,264,{"Meat","Joe Camp"}}; getDogInfo(cujo); getDogFavs(cujo); dog cujo2=cujo; //same object; different reference getmemoryLocations(cujo); getmemoryLocations(cujo2); setDogWeight(cujo,11); getDogInfo(cujo); /* weight is still 264. Why is that ? when a struct is passed in as a parameter, a new struct is created and get passed in ! */ setDogWeightPtr(&cujo,11); getDogInfo(cujo); //correct way }
void main(){ // We are going to use struct dog here // To define it here we do the next: // 1. We are going to give it a name // 2. Define a breed // 3. Define average height in centimeters // 4. Define average weight in lbs // 'cujo' here is a variable name struct dog cujo = {"Cujo", "Saint Bernard", 90, 264}; // And now it will be easy to get all this information // using an individual function getDogInfo(cujo); // Here we will create another dog struct // And we will give it a data that is currently in 'cujo' struct dog cujo2 = cujo; getMemoryLocation(cujo); getMemoryLocation(cujo2); }