time_t t; Which one of the following statements will properly initialize the variable t with the current time from the sample above

  1. t = ctime();

  2. time( &t );

  3. t = localtime();

  4. t = clock();


Correct Option: D

AI Explanation

To properly initialize the variable t with the current time, you can use the time() function from the ctime library.

Option A) t = ctime(); - This option is incorrect because the ctime() function returns a string representation of the current time, not the actual time value.

Option B) time( &t ); - This option is correct because it calls the time() function and passes the address of t as an argument, allowing time() to store the current time value in t.

Option C) t = localtime(); - This option is incorrect because the localtime() function converts a time value into a broken-down time structure, not the current time.

Option D) t = clock(); - This option is incorrect because the clock() function measures the processor time, not the current time.

The correct answer is Option B.

Find more quizzes: