I’m trying to understand a part of my professor’s code. He gave an example for a hw assignment but I’m not sure how to understand this part of the code..
Here is the code:
void addTask(TaskOrAssignment tasks[], int& taskCount, char *course, char *description, char *dueDate)
{
tasks[taskCount].course = course;
tasks[taskCount].description = description;
tasks[taskCount].dueDate = dueDate;
taskCount++;
}
Question: Is “tasks[taskCount].course = course;” accessing or declaring a location for char course?
I hope I could get this answered and I’m pretty new to this site too.
Thank you.
Let’s break this down a piece at a time. First of all, we are using the assignment operator (=) to assign a value of one variable to another variable.
The right hand side is pretty simple, just the variable named
coursewhich is declared as achar*.It is assigned to the variable
tasks[taskCount].course. If you look at the parameters of the method, you can see thattasksis declared as an array ofTaskOrAssignmentobjects. Sotasks[taskCount]refers to one of the elements of this array. The.courseat the end refers to a field namedcoursein that object. Assuming that this code compiles, that field is declared as achar*in theTaskOrAssignmentclass.Most likely, both
coursevariables represent a string of characters. (This originates from C.) When all is said and done, bothcourseandtasks[taskCount].coursepoint to the same string buffer.