A brief review of JNI in C Language

Source: Internet
Author: User

I. Basic data types of C language:
Char, Int, float, double, signed, unsigned, long, short and void in C Language
// Eight data types and their lengths in Java
// Byte 1 char 2 short 2 int 4 long 8 double 8 float 4 Boolean 1

// C language in the c99 standard. No byte type, no Boolean Type
// In C, 0 indicates false, not 0 indicates true.
// Sizeof (); get the length of a data type and accept a parameter (data type)

// In C, the char type is 1 byte. in Java, the char type is 2 bytes.
// The Char length in C is the same as the byte length in Java. Therefore, the char type in C can be used to represent the byte type in Java.
// Int in C language and INT in Java have the same length in memory, so the int in Java and INT in C language can be used in place of each other.
 
// In C, the long type is 4 bytes. in Java, the long type is 8 bytes.

II. C Language Input Functions
// Scanf ();
// In Java, there is a data type called string.
// No string type in C Language
// C indicates an array of characters defined by a string
// Use scanf % s to conveniently obtain a string from the keyboard

3. Pointer entry:
// The pointer represents a memory address, which can be expressed by a pointer.
// The address is the ID of a piece of memory space. With this ID, we can use a piece of memory space.

// Pointer variable: Variable pointer variable that can store pointer type (memory address data) data.
// Use * to indicate pointer variables.
// Int * Indicates a variable that represents the int data address.

Add.
// The first function of 3*5 1. * represents the multiplication operation.
// 2. Keep up with a "*" after a data type to indicate that it is a pointer variable of this data type.
// 3. Adding a * sign before a pointer variable indicates accessing the content stored in the address in the pointer variable.
Function pointer

INT (* PF) (int x, int y); // defines a pointer to a function. The return value of this function is int. Two int-type parameters are accepted.

4. Common pointer errors:
Common Pointer Error 1:
 
 
// The pointer variable type must correspond to the data storage type
// The Int type variable address must be represented by int.
// The address of the float type variable must be represented by float.

Common Pointer Error 2:
Int I = 5;
Int * P;
Printf ("* P = % d \ n", * P); // If the P variable is not initialized, it contains a garbage value.
// * P accesses an unknown memory (wild pointer)

// Pointer variables are not assigned values and cannot be used.
// If you modify the memory space pointed by a wild pointer, a serious error may occur.

// The Window operating system provides some APIs to enhance the permissions of the parent process.

5. pointer Length

// The pointer length of all data types is 4 bytes
// A 32-bit operating system.
// The role of the pointer type is to work during pointer operations and to obtain the data pointed to by the pointer.
6. Multilevel pointers

7. Manually allocate memory
Stack memory will be automatically recycled by the system and cannot be manually recycled
The heap memory will not be automatically recycled by the system and needs to be manually recycled by the programmer.

8. struct, Consortium and enumeration, custom type
Struct:
Struct student // This is the most standard way
{
Int age; // 4
Float score; // 4
Long ID; // 4
Char C; // For ease of processing, it is also allocated to 4

// Different compilers may process different results.
};

Three methods:

First
Struct student
{
Int age;
Float score;
Char sex;
}

Second
Struct student2
{
Int age;
Float score;
Char sex;
} St2;

Third
Struct
{
Int age;
Float score;
Char sex;
} St3

Consortium
Union {double D; long I; int K; char II;} mix;

Typeof defines an alias for a variable.

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.