34.5k views
1 vote
When an integer is subtracted from a pointer variable, the value of the pointer variable is decremented by the integer times half the size of the memory to which the pointer is pointing.

True

False

1 Answer

3 votes

Answer:

False

Step-by-step explanation:

When you apply subtraction (arithmetic operation) on Pointer variable ,then pointer variable is decremented by the (integer*sizeofmemory).

Example

#include<stdio.h>

//driver function

int main()

{

float *ptr=(float *)100; //initializing ptr as pointer type

ptr=ptr-2; //subtracting pointer by 2(integer)

printf("New Value of ptr is %u",ptr);

return 0;

}

Output

New Value of ptr is 92

Explanation of Code

ptr = ptr - 2 * (sizeof(float))

= 100 - 2 * (4) //float size is 4 bytes

= 100 - 8

= 92

User Conorsch
by
7.0k points