answersLogoWhite

0

When a pointer to a data type that requires four bytes is declared, the compiler knows that the target object is four bytes in size. When the program then performs a calculation to offset the pointer, such as to add 3 (for instance) to the pointer, the generated code actually adds 12. This is because the compiler assumes that adding or subtracting numbers to or from a pointer is an attempt to use the pointer in an array context. (Actually, this behavior is defined in the language specification.)

The other valid arithmetic manipulation of a pointer is subtraction of two pointers to the same type of object. In this case, again, an internal multiplier of 4 is applied, and the result is an offset that could be used if the first pointer were the base of an array of those objects.

The size of the target object could be any value, such as a double which might be 8 bytes. The compiler will do the arithmetic correctly.

Also, keep in mind the distinction between the size of the pointer and the size of the object to which the pointer points. This answer assumes the latter.

In any case, the programmer must insure that the calculation results in a pointer or offset value that represents an address in the base object array, assuming that the allocated space of that object is correct. Any other result is inconsistent with the defined usage of a pointer, and the result of dereferencing such an inconsistent pointer or offset is undefined by the language specification, and could result in corruption, incorrect behavior, or crash.

User Avatar

Wiki User

15y ago

What else can I help you with?

Continue Learning about Engineering

What Pointer in Data Structure?

No, pointer is not a data type but a reference to an object. Pointers are used to refer back to an object which can be anything from a large data value or a collection of values or objects.A pointer is a variable and is 4 bytes long because 4 bytes = 32 bits, and all addresses in 32 bit operating systems are 4 bytes long :) , so if you want to store an address somewhere you need 4 bytes. A pointer is just 4 bytes in the memory and in these 4 bytes an address is stored. If you ask the address of an element, like char, int, etc., the address you will get will be the address of the first byte. Only the first byte is saved in the pointer, and then you can manipulate the upcoming bytes.For example you declare a structure of 12 bytes and you name it myStruct.let's say that the address of this structure is the address 0x00400001


What is double in 'c' language?

The double data type is a fundamental numeric data type that can represent floating point values. Depending on implementation, it is normally 8 bytes in size, with a precision around 18 decimal digits.


How big in bytes are each of the 6 numeric primitive data types?

boolean - 1 bit (1/8 bytes) - The actual storage requires for a boolean type is not defined for Java implementations.byte - 1 byteshort - 2 bytesint/char - 4 byteslong - 8 bytesfloat - 4 bytesdouble - 8 bytes


Who decides size of data types in a language?

The people who create the language take the liberty of deciding the size of data types in a programming lanauage.If you (as a programmer) create your own custom data type, for example by defining a class, then you decide what goes into it - for example, in Java, if one of the pieces of data requires an integer, you have the choice of storing it as an int, which uses 4 bytes, or as a long, which uses 8 bytes (and permits larger numbers).


What is difference between pointer and structures?

pointer data type that carry address:of data type that has no name but both of them must have same data type. structures you can make your own data type: struct name put any data type you wants any functions.

Related Questions

What Pointer in Data Structure?

No, pointer is not a data type but a reference to an object. Pointers are used to refer back to an object which can be anything from a large data value or a collection of values or objects.A pointer is a variable and is 4 bytes long because 4 bytes = 32 bits, and all addresses in 32 bit operating systems are 4 bytes long :) , so if you want to store an address somewhere you need 4 bytes. A pointer is just 4 bytes in the memory and in these 4 bytes an address is stored. If you ask the address of an element, like char, int, etc., the address you will get will be the address of the first byte. Only the first byte is saved in the pointer, and then you can manipulate the upcoming bytes.For example you declare a structure of 12 bytes and you name it myStruct.let's say that the address of this structure is the address 0x00400001


How much data can be stored in a system that has a capacity of 232 bytes?

A system with a capacity of 232 bytes can store 4,294,967,296 bytes of data.


What is double in 'c' language?

The double data type is a fundamental numeric data type that can represent floating point values. Depending on implementation, it is normally 8 bytes in size, with a precision around 18 decimal digits.


An Ethernet MAC sublayer receives 42 bytes of data from the upper layer. How many bytes of padding must be added to the data?

The padding needs to make the size of the data section 46 bytes. If the data received from the upper layer is 42 bytes, we need 46 − 42 = 4 bytes of padding.


An Ethernet MAC sublayer receives 42 bytes of data from the upper layer. How many bytes of padding must be added to the data Why?

The padding needs to make the size of the data section 46 bytes. If the data received from the upper layer is 42 bytes, we need 46 − 42 = 4 bytes of padding.


What is a tarabyte?

For point of reference 1Million Bytes of data = 1 Megabyte 1Billion Bytes of data or 1000 million = 1 Gigabyte 1Trillion Bytes of data or 1000 Billion = 1 Tarabyte


Why do pointer occupy only 2 bytes of memory in 16 bit DOS environment?

You've answered your own question, I'm afraid. A 16-bit memory address requires 2 bytes of storage (8 bits * 2 bytes = 16 bits). Note that, without using XMS or EMS, you can only address 2^20 bytes of memory, with the last 384k or so being restricted (BIOS, video, etc) unless you enable the A20 line (it actually wraps from FFFF:0010 back to 0000:0000). Also, you should note that 16-bit pointers work because of a "segment:offset" feature; your current "data segment" determines where in memory your pointer actually points to. If you need a 4-byte pointer, use a far pointerinstead; these pointers can reference any point in memory (up to the aforementioned 1MB limit).


What is uninitialised pointer?

A pointer is an address or the name for the location for an item of data. An uninitialised pointer is one that has not been assigned an initial value or item of data.


What is bytes mega bytes and giga bytes?

bytes, megabytes and Gigabytes are the units for measuring the amout of data on a computer. 1024 megabytes are a gigabyte


Why you need to consider bytes in making a website?

Because the less bytes used the more bytes saved. This means that your site can contain more data or have more data entered into it.


Units for data measurement?

bytes , kilobytes , megabytes , gigabytes , tetra bytes etc.


Difference between void pointer and null pointer?

A Null pointer has the value 0. void pointer is a generic pointer introduced by ANSI. Before ANSI, char pointers are used as generic pointer. Generic pointer can hold the address of any data type. Pointers point to a memory address, and data can be stored at that address.