Both work correctly in my simple test code, but I would like to know if there is any real difference or any agreed preferences in coding styles.
An example of the attached code:
#include <stdio.h> #include <time.h> int main(int argc, char **argv) { time_t now1, now2; time(&now1); now2 = time(NULL); printf("now1 = %ld\n", now1); printf("now2 = %ld\n", now2); return 0; }
EDITI just saw Keith Thompson's answer - This question should probably be marked as a duplicate.
There is no difference between them.
If you do this:
time_t now1, now2; now2 = time(&now1);
Both now1and now2will have the same value.
now1
now2
, , Linux 2.4 64- . time , 32 ( time_t - 64-). , , , time_t, , .
time
time_t
, : NULL, (, xor ingoing ( )), ( ), , () , , , , ( : ), .
NULL
xor
- ?
.
time_t now1, now2; time(&now1); now2 = time(NULL);
time_t now3 = time(NULL);, RAII , - OP 2.
time_t now3 = time(NULL);
?
, , . , .
. , int return, - .
int
Source: https://habr.com/ru/post/1672247/More articles:How to find out if libcurl processed my SSL files correctly - c ++Datomic: schema for many relationships with reset operation - database-designAzure routed host application in Azure - angular500 for the long iis7 url - urlForce client to check. Acknowledgment that they read the document - phpHow to create a valid, self-signed X509Certificate2 programmatically without loading from a file in .NET Core - c #How to disable comments on the "branch"? - javascriptAdmob Reward Video Ads не работает с тестовыми устройствами - androidGriddle v1 onRowClick doesn't fire - reactjsWhy is the episode done after 200 time steps (MountainCar Gym)? - pythonAll Articles