Basic data types for C language Basics-Other integer types

Source: Internet
Author: User

Other integer types

When you beginner C, the int type will satisfy most of your needs for integers.

The C language also provides three keywords to modify basic integer types: short, long, and unsigned. Here are a few points to note:

(1) The C language does not specify the number of bytes of memory for each type of data, only the long data is longer than or equal to the int type, short data is shorter than or equal to the long type. Thus the short int type may occupy less storage space than the int type. Space-saving applications where small values are required. Like the int type, the short type is a signed type .

(2) The long int type may occupy more storage space than the int type. is also a signed type.

(3) The unsigned int type is used for applications where only non-negative values are used. This type differs from the representation range of a signed type. For example, a 16-bit unsigned int has a range of 0 to 65535, while an int has a range of 32768 to 32767. So when choosing an integer type, consider the unsigned type first if you don't need a negative number. Unsigned types can achieve a larger positive number than the signed type, and can enhance readability.

Output unsigned int numbers can use the%u notation, the output long value can use the%ld specifier, and the symbol%HD can be used to output the short int type.

Let's see an example:

#include <stdio.h> int main (void) {//declares a variable of type long int, the variable is named Money, and initializes it, and then outputs the variable//write down your code here      long int money = 1;          printf ("%ld", money);  return 0; }

more learning content, just in the code bud Net Http://www.mayacoder.com/lesson/index


Basic data types for C language Basics-Other integer types

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.