# Sizeof function definition in a system

Why sizeof(int) and sizeof(int *) takes different value in a system? I mean generally size of integer is 4 B, but size of integer pointer is 8 B. But why they cannot take same value, although their return type is same?

• What do you mean by "their return type is the same"? – Yuval Filmus Apr 6 '19 at 16:04
• @YuvalFilmus I'm not sure it matters, since this question is purely about a feature of the C language, which is off-topic, here. But I agree this should be clarified when the question is asked on Stack Overflow. – David Richerby Apr 6 '19 at 16:09
• I mean one is integer variable and another is integer pointer. Both integer type . – Srestha Apr 6 '19 at 16:15
• They're not the same type. One is an integer, another is a pointer, i.e., a memory address. See en.wikipedia.org/wiki/Pointer_(computer_programming). – Yuval Filmus Apr 6 '19 at 16:22
• @DavidRicherby This is a rather general question, which has little to do with C. It is about the difference between pointers and what they point at. – Yuval Filmus Apr 6 '19 at 16:23

An integer is a value, whereas a pointer to an integer is a pointer, that is, a memory address. In most systems, all pointers have the same size, but the objects they point to can have different sizes. For example, in your systems pointers are 8 bytes long, whereas integers come in various sizes — possibly from 1 byte up to 8 bytes.

You might be misled by the specific quirky syntax of C, which allows declarations of the form

int a, *b;


This declares an integer a and a pointer b. This is just a confusing feature of C syntax.

• "whereas integers come in various sizes — possibly from 1 byte up to 8 bytes. "-Can you tell me how? – Srestha Apr 6 '19 at 19:51
• This is already getting to be specific to the C programming language. C has several integer datatypes, which generally have different sizes, though the exact sizes are implementation-dependent. Any good text on C would cover these. – Yuval Filmus Apr 6 '19 at 19:53
• You mean size of integer can be 2B or 4B or 8B in 64bit system? Then pointer size also can vary, right? – Srestha Apr 6 '19 at 19:59
• On modern systems pointer sizes don't vary. There's certainly no reason for them to vary depending on what they are pointing at. See stackoverflow for the situation in the past. The available integer sizes depend on the system. See Wikipedia. – Yuval Filmus Apr 6 '19 at 20:03
• Sizeof(int) is entirely up to the C compiler except it must be >= 1. It could be 42. Which would be unusual, but entirely possible. – gnasher729 Apr 7 '19 at 11:01