Introductory tutorials for basic data types in the C language

Source: Internet
Author: User

1. Declaration header file, equivalent to the Java Guide package.

Only the declaration of the function, compile-time will find the implementation of the function
#include <stdio.h>
2. Write Main () method

Main () {
printf ("Hello from c\n"); \ n Line Change
}
3. In order to observe the results of the program execution, you need to invoke an instruction from the Windows system

Wait for input
System ("pause"); or GetChar ();


Basic data types for C language

C-language data type:


8 basic types of the Java language

int 4byte 32-bit
BYTE 1byte 8 bits
Short 2byte 16-bit
Long 8byte 64 bits
Float 4byte 32-bit
Double 8byte 64-bit
Boolean 1byte 8-bit
Char 2byte 16-bit
Basic data types for C language

sizeof (); Gets the length of a data type

Char 1byte 8 bit differs from Java
Long 4byte 32 bit differs from Java
int 4byte 32 bit and Java consistent
Float 4byte 32 bit and Java consistent
Double 8byte 64 bit and Java consistent
Short 2byte 16 bits can also represent the char inside Java
There is no Boolean type in the C language, 0 false non 0 true
There is no byte type in C language that can be used to represent byte types.
The code is as follows:

/**
char, int, float, double, long, short and combined keywords signed, unsigned, void
sizeof (); Gets the length of a data type
**/
#include <stdio.h>
Main () {

printf ("Char occupies a byte of%d \ n", sizeof (char));
printf ("byte occupied by int \ n", sizeof (int));
printf ("float occupies byte%d \ n", sizeof (float));
printf ("A double occupies a byte of%d \ n", sizeof (double));
printf ("A long occupies a byte of%d \ n", sizeof (long));
printf ("Short occupies byte%d \ n", sizeof (short));

printf ("Signed int occupies a byte of%d \ n", sizeof (signed int)); -2 of the 31 times to 2 of 31 Times Square-1
printf ("Unsigned int occupies a byte of%d \ n", sizeof (unsigned int)); 0~ 2 of the 32-time Square-1

printf ("int* occupies byte%d \ n", sizeof (int*));
printf ("char* occupies byte%d \ n", sizeof (char*));
printf ("float* occupies byte%d \ n", sizeof (float*));
printf ("double* occupies byte%d \ n", sizeof (double*));
printf ("long* occupies byte%d \ n", sizeof (long*));
printf ("short* occupies byte%d \ n", sizeof (short*));


System ("pause");

}
The results of the operation are as follows:

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.