JASON
JASON

Reputation: 7491

Understanding some C++ code

I dont understand the part: struct tm * timeinfo; what does this mean? Why there's a star there? Thanks!

int main ()
{
  time_t rawtime;
  struct tm * timeinfo;

  time ( &rawtime );
  timeinfo = localtime ( &rawtime );
  printf ( "The current date/time is: %s", asctime (timeinfo) );

  return 0;
}

Upvotes: 0

Views: 167

Answers (4)

Clifford
Clifford

Reputation: 93556

localtime() returns a pointer to an internal copy of a tm structure. struct tm* declares a pointer to a tm struct.

Upvotes: 0

zhongshu
zhongshu

Reputation: 7878

That's a pointer in C/C++. Pointer is a basic function of C language.

Upvotes: 0

Sarfaraz Nawaz
Sarfaraz Nawaz

Reputation: 361712

struct tm * timeinfo;

It's declaring a variable timeinfo of type struct tm*. This is C-syntax.

In C++, you don't need to write struct keyword. Just tm * timeinfo is enough!

Upvotes: 2

bmargulies
bmargulies

Reputation: 100151

If you really don't know how pointers are declared in C++, you need to do more reading than will fit into an answer here. The * declares pointer to.

Upvotes: 4

Related Questions