+ 3

Size of int and pointer variables

Which all are the factors depends on the size of the integer and size of the pointer variable..? Are there any relationship between size of the integer and size of the pointer?

15th Jan 2019, 5:08 PM
punnoose
6 ответов
+ 4
A pointer holds a memory address, its size doesn't depend on the type of the data it points to. On 64-bit systems, it is 8-byte long (8*8 = 64). As for integers, it is basically 4-byte long nowadays, but if you want a more complete answer, look here: https://stackoverflow.com/questions/11438794/is-the-size-of-c-int-2-bytes-or-4-bytes Also, as Ipang said, sizeof(int) will give you the size of int in bytes.
16th Jan 2019, 10:10 AM
Zen
Zen - avatar
+ 1
Maybe this wiki article can give a little insight: https://en.m.wikipedia.org/wiki/Sizeof P.S. Looking forward to hearing some insights from experts over this.
15th Jan 2019, 6:10 PM
Ipang
+ 1
Declarating a variable of certain Kind will Tell the Programm and the OS how much memory in the Stack needs to be reserved to hold the value of the assigned variable
17th Jan 2019, 7:06 AM
Pascal Pizzini
Pascal Pizzini - avatar
+ 1
Firstly size of the int and the pointer are both compiler dependent.. But we generally take 16 bit as reference and take the size of int as 2 bytes and pointer also 2 bytes.... Pointer size is decided by that it should hold the max lage address according to the architecture.. The size of the int or any other data type is responsible for the the max value that it can store.. If the value goes out of range of the datatype then it will retun an unexpected output and can cause logical errors in the program.. But as pointer only stores the address of the datatype so we do not need to worry about its size... No there is no relationship between in terms of size... But if we make a pointer of type int then it can hold only addresses of int type..
17th Jan 2019, 3:25 PM
Rohit
Rohit - avatar
0
If you create a Pointer of a Type, Like int, this Pointer can only Point to Adresse, referred to variables, that are also int, since Pointer do Point to an adress of a variable, they can only keep as much or less content saved to this adress
17th Jan 2019, 8:50 AM
Pascal Pizzini
Pascal Pizzini - avatar
- 1
Nbhbgyhheg
7th Feb 2019, 1:11 PM
Priyanshi Gupta