size_t/ptrdiff_t/intptr_t/uintptr_t

Source: Internet
Author: User

1.size_t

size_t is an unsigned integer type, which is the type of the sizeof operator result. If the device has an address space of 32 bits, this is a 32-bit unsigned integer, and if the device's address space is 64 bits, this is a 64-bit unsigned integer. In other words, a variable of type size_t can safely hold a pointer (the only exception is a pointer to a class function). size_t are typically used for loop counters, array indexes, and address arithmetic.

2.ptrdiff_t

Ptrdiff_t is a signed integer type, which is the type of two pointer subtraction results. If the device has an address space of 32 bits, this is a 32-bit signed integer, and if the device's address space is 64 bits, this is a 64-bit signed integer. As with size_t, ptrdiff_t can safely store pointers other than class function pointers.

The size of the size_t and Ptr_diff is always the same size as the pointer, so it is suitable for indexing large arrays, storing pointers, and pointer operations.

3.intptr_t

Signed integer type, which has a property, any legal pointer to void can be converted to this type, and then can be converted back to a pointer to void, the result is equal to the original pointer comparison.

4.uintptr_t

An unsigned integer type that has a property that any legitimate pointer to void can be converted to that type, and can then be converted back to a pointer to void, with the result being equal to the original pointer comparison.

size_t/ptrdiff_t/intptr_t/uintptr_t

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.