devxlogo

More about sizeof() operator

More about sizeof() operator

Question:
I’m using the sizeof() operator to find the length of my integers just like the Q&A section said, but it consistently returns a 4 regardless of integer length. What could be causing an error like this?

Answer:
I’m more puzzled trying to determine exactly what it was you were expecting sizeof() to do.

sizeof() returns the number of bytes a variable, or variable type, occupies. Your particular compiler apparently implements long integers, which each take up 4 bytes.

This is normal behavior.

devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist