Skip to content

Subtraction between two pointers of the same type results in the number of bytes(codecast) and not the number of elements (gcc). #626

@kambadur

Description

@kambadur

The program prints the start and end pointers of an array. Then it is asked to print the difference which is supposed to be the number of elements as both are pointers of type (int*) and shall return the number of elements 5 (gcc on my local linux) and not the number of bytes 20 (codecast terminal output).

`
#include <stdio.h>

int main(void){
//! showMemory(start=65530)
int arr[6]={10, 20, 30, 40, 50, 60};
int * startPtr = arr;
int * endPtr = &arr[5];

printf("%p  %p\n", startPtr, endPtr);
printf("%td\n",(endPtr-startPtr));
return 0;

}
`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions