Blog

Is it possible to multiply pointers?

Is it possible to multiply pointers?

yes it is allowed, *x is not a pointer but a value pointed by x . It multiplies or divides the pointed at values, and the pointed at values are not pointers, so multiplication and division is fine.

Can a pointer point to a value?

When you create a pointer variable, initially it will have garbage value (let say 300 address location). Hence when you dereference pointer(*300), it would give another garbage value(value at 300 address location) or error (strictly speaking anything may happen depending on your computer).

Can we add 2 pointers in C?

Pointers contain addresses. Adding two addresses makes no sense because there is no idea what it would point to. Subtracting two addresses lets you compute the offset between the two addresses. An array name acts like a pointer constant.

READ ALSO:   What kind of spider has a black body and red legs?

Can a pointer be added to another pointer?

Pointer assignment between two pointers makes them point to the same pointee. Pointer assignment does not touch the pointees. It just changes one pointer to have the same reference as another pointer. After pointer assignment, the two pointers are said to be “sharing” the pointee.

What is value of pointer?

A pointer is a variable whose value is the address of another variable, i.e., direct address of the memory location. Like any variable or constant, you must declare a pointer before using it to store any variable address.

Can pointers point to the stack?

Pointer pointing to stack or heap? So any object created on stack will have an address between these two pointers. So if we get a pointer, just check whether the pointer falls between the above two memory locations. If it does, then it can be considered a pointer to some stack object.

Why is two pointers impossible?

Because pointers represent locations in the memory. Each pointer is the address of a block in the memory. Subtracting two pointers will give you the size of memory between them. Addition or any other mathematical operation on values of pointers has no meaning.

READ ALSO:   How difficult are Uber interviews?

Can pointers be added or subtracted?

The subtraction of two pointers is possible only when they have the same data type. The result is generated by calculating the difference between the addresses of the two pointers and calculating how many bits of data it is according to the pointer data type.

Which operation is not allowed on pointers?

Addition, subtraction, multiplication and division are not allowed but pointers can be subtracted to know how many elements are available between these two pointers.