• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 547
  • Last Modified:

Trying to find out time_t size and i have 4 bytes?

Hi there;

I am trying to find a time_t struct size and what I have got is 4 bytes. Isn't it 8 bytes?

Here you go, for the code;

Kind regards.
# include <stdio.h>
# include <iostream>
# include <time.h>
using namespace std;
size_t getPtrSize( char *ptr )
	return sizeof( ptr );

int main()
	time_t lt;

	lt = time(NULL);
	cout << "Date: " << ctime(&lt) << endl;

	cout << "\nThe length of " << ctime(&lt) << " is: "
		 << sizeof ctime(&lt)
		 << "\nThe size of the pointer is "
		 << getPtrSize( ctime(&lt) ) << endl;

	return 0;

Open in new window

  • 2
3 Solutions
Try using

cout << sizeof(time_t);

Address of pointers is always the same irrespective of the data type
jazzIIIloveAuthor Commented:
Ok, working.

But why 4, not 8 with my code? I mean, could you explain that, before I conclude this question?

Sizes are dependent upon your architecture.

Sizes of integers vary.  Sizes of pointer even vary.  If you run your code on anther machine, you may see a different value.

See this
and search for "size in memory"
evilrixSenior Software Engineer (Avast)Commented:
Just to clarify what farzanj has already said...

>> But why 4, not 8 with my code?
Because on your architecture a pointer is 4 bytes (32 bits).

>> Isn't it 8 bytes?
No. From the C standard: The range and precision of times representable in clock_t and time_t are implementation-defined.

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now