user2096942
user2096942

Reputation: 31

Dereferencing a function returning a pointer to a structure in C

I've recently come across the following behaviour in C code for the first time:

struct tm brokenDownTime = *gmtime( &myTime );

gmtime returns a pointer to a tm structure and I can see that it's being dereferenced, am I right in assuming that the * is causing the structure to be copied?

Many thanks

Upvotes: 3

Views: 1124

Answers (1)

Bathsheba
Bathsheba

Reputation: 234645

Almost correct, the deference itself doesn't cause the copy but the assignment does: all the structure elements are shallow copied.

Upvotes: 7

Related Questions