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: