tm_year << endl; in ctime lib why we must use ltm->tm_year but can't use *1tm.tm_year" /> tm_year << endl; in ctime lib why we must use ltm->tm_year but can't use *1tm.tm_year" /> tm_year << endl; in ctime lib why we must use ltm->tm_year but can't use *1tm.tm_year"/>

ctime lib, pointer in C++

80 Views Asked by At
tm *ltm = localtime(&now);
cout << "Year: "<< 1900 + ltm->tm_year << endl;

in ctime lib why we must use ltm->tm_year but can't use *1tm.tm_year

1

There are 1 best solutions below

0
pm100 On

Because of the precedence of operators in c++

*1tm.tm_year

means

  *(1tm.tm_year)

you can do

   (*1tm).tm_year

but thats a bit ugly, hence this:

  1tm->tm_year