Learn point C language (15): Data type

Source: Internet
Author: User
Tags include printf

The variable that gets the type size is best not the int type, but the size_t type;

size_t are defined in stdio.h and stddef.h.

1. Get the size of a known type:

#include <stdio.h>
#include <stddef.h>

int main (void)
{
char n = 2;
size_t size;

size = sizeof (char);
printf ("%*u:char\n", n,size);

size = sizeof (unsigned char);
printf ("%*u:unsigned char\n", n,size);

size = sizeof (short);
printf ("%*u:short\n", n,size);

size = sizeof (unsigned short);
printf ("%*u:unsigned short\n", n,size);

size = sizeof (int);
printf ("%*u:int\n", n,size);

size = sizeof (unsigned);
printf ("%*u:unsigned\n", n,size);

size = sizeof (long);
printf ("%*u:long\n", n,size);

size = sizeof (unsigned long);
printf ("%*u:unsigned long\n", n,size);

size = sizeof (long long);
printf ("%*u:long long\n", n,size);

size = sizeof (unsigned long long);
printf ("%*u:unsigned long long\n", n,size);

size = sizeof (float);
printf ("%*u:float\n", n,size);

size = sizeof (double);
printf ("%*u:double\n", n,size);

size = sizeof (long double);
printf ("%*u:long double\n", n,size);

size = sizeof (wchar_t);
printf ("%*u:wchar_t\n", n,size);

GetChar ();
return 0;
}

Related Article

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.