159k views
2 votes
A function that accepts a structure (not a pointer to a structure) as an argument receives a copy of the structure.

TRUE
FALSE

1 Answer

3 votes

Final answer:

FALSE. A function that accepts a structure (not a pointer to a structure) as an argument does not receive a copy of the structure. Instead, the function receives a pointer to the structure, which allows it to modify the original structure.

Step-by-step explanation:

FALSE

A function that accepts a structure (not a pointer to a structure) as an argument does not receive a copy of the structure. Instead, the function receives a pointer to the structure, which allows it to modify the original structure. If a copy of the structure is needed, it can be explicitly created within the function. Here's an example:

struct Student {
int id;
char name[50];
};

void updateStudent(struct Student s) {
s.id = 1001;
strcpy(s.name, "John");
}

int main() {
struct Student myStudent;
myStudent.id = 999;
strcpy(myStudent.name, "Jane");
updateStudent(myStudent);
printf("ID: %d, Name: %s", myStudent.id, myStudent.name);
return 0;
}

In the example, the updateStudent function does not make a copy of the Student structure. Instead, it receives a pointer to the original structure, allowing it to modify the values. If the function made a copy, the changes would not affect the original structure.

User EnriqueBet
by
7.8k points