Android For JNI (2) -- data type, output, input function, Operation memory address, and memory modifier in C Language

Source: Internet
Author: User

Android For JNI (2) -- data type, output, input function, Operation memory address, and memory modifier in C Language
Android For JNI (2) -- data type, output, input function, Operation memory address, and memory modifier in C Language

After writing Hello World, we can enter the gate of C. Today we will talk about some basic data types and functions.

Let's first look at a picture that has been spreading for a long time'

1. Various Data Types

Integer types include short integer, integer, and long integer.

Short integer

Short a = 1;

Integer

It generally occupies 4 bytes (32 bits). The highest bit represents the symbol. 0 represents a positive number. 1 represents a negative number. The value range is-2147483648 ~ 2147483647. The storage order in the memory is after the top and high positions. For example, the storage of 0x12345678 in the memory is as follows:

Address: 0x0012ff78 0x0012ff79 0x0012ff7a 0x0012ff7b

Data: 78 56 34 12

Definition: Use the int keyword, for example:

Int a = 6;

Long Integer

Long a = 10;

Floating Point Type

Floating Point models include single-precision and double-precision models.

Single precision type

Float Type, also known as solid type, also known as single precision. It generally occupies 4 bytes (32 bits ),

Float a = 4.5;

Address: 0x0012ff78 0x0012ff79 0x0012ff7a 0x0012ff7b

Data: 00 00 90 40

Double Precision type

Generally 8 bytes (64-bit)

Double a = 4.5;

Address: 0x0012ff78 0x0012ff79 0x0012ff7a 0x0012ff7b 0x0012ff7c 0x0012ff7d 0x0012ff7e 0x0012ff7f

Data: 00 00 00 00 00 12 40

Character Type

In various systems, the character type occupies one byte (8 bits ). Definition:

Char c = 'a ';

You can also assign values using the ASCII code corresponding to the characters, as shown below:

Char c = 97;

In fact, we can use a string of code to illustrate the above meaning

# Include
  
   
# Include
   
    
Main () {// basic data type: char int float long short double signed unsigned int I = 3; char a = 'C '; // int format specifier % d printf ("I value: % d", I ); // char format specifier printf ("the value of a is % c", a); system ("pasue "); // general output system ("general output % d", sizeof (short )); // usage of char int float long shortd is similar to that of JAVA // Let's mention signed unsigned // signed: signed unsigned // example signed int I = 3; // It is divided into positive and negative unsigned int i2 = 3; // no matter whether it is positive or negative // The Byte Length char 1 int 4 float 4 long 4 short 2 double 8}
   
  

Is it clear, but we have come from JAVA, which can basically be taken over. Let's take a look at the functions in C.

Ii. Output Functions

Let's take a look at the output functions mentioned above.

% D-int % ld-long int % lld-long % hd-short integer % c-char % f-float % lf-double % u-Unsigned Number % x- hexadecimal output int, long int, or short int % o-octal output

% S-string

Int len;

Scanf ("% d", & len );

Because this is not in JAVA, I 'd like to mention it here

// The array [] of C should be written behind it, and the length of this array is 8, because it has an ending character \ 0 char str [] = {'A ', 'N', 'd, r, o, I, d,}; char str [] = "can be entered "; // 9 bytes
Iii. Input Functions

There are no strangers to the input functions, as well as JAVA code.

import java.io.*;public class Test1 {/** * @param args * @throws IOException  */public static void main(String[] args) throws IOException {    BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));    String str = stdin.readLine();    System.out.println(str);}}

In this way, you can enter something in the console, but C is much simpler. the scanf ("% d", & len) function is also mentioned above. Let's take a look at how to use it.

# Include
  
   
# Include
   
    
// Input function main () {printf ("Enter your age:"); // define a variable int age; // set the input type to int scanf ("% d", & age); printf ("your age is % d \ n", age ); system ("pause ");}
   
  

Run the following command:

So OK.

Iv. Memory Address

Memory, C can be operated directly. This is his advantage, and it is also a hard part for him. We have to make a good effort, the memory address is the memory address, so data is obtained through the address in the memory, just like findviewbyid. Let's look at an example.

# Include
  
   
# Include
   
    
Main () {int I; // when I is declared, a space is opened in the memory, four bytes, no value, and an address I = 5 is allocated; // give the address a value of printf ("% d \ n", I ); // when we want to output this I, we actually get this 5 address // get the memory address printf ("% # x", & I ); // Let the window stay at int age; scanf ("% d", & age );}
   
  

We can use this line of code to obtain the I value and the I address and print the result.

For a more vivid explanation, for example, the computer system is distinguished by 32-bit and 64-bit, and the 32-bit system supports a maximum of 4 GB memory, this is because the length of the 32-bit system memory bus is 32, that is, the number that can be allocated to the memory as the address is the power of 2.

5. Memory Modifier

Modify the memory. Just like playing a game, if your blood volume is 100, you define a variable in the memory, such as int blood = 100, which opens up a space in the memory, assign a value of 100 and perform other operations. Let's write a small example.

# Include
  
   
# Include
   
    
Main () {// time 60 s int time = 60; int I; // print I address printf ("% # x \ n", & I ); for (I = time; I> = 0; I --) {printf ("Remaining time: % d \ n", I); // sleep, sleep (1000);} // Let the window stay at int age; scanf ("% d", & age );}
   
  

The logic should be clear. Let's define an I, get his memory address, and let him perform the same countdown operation. This simulates playing games, such as games within one minute of customs clearance, we modified the memory of I to achieve the memory modifier effect.

Then we can download the Cheat Engine. This is the memory modifier, which is similar to the principle of the Cheat Engine.

Find it online by yourself. For specific usage, Baidu

After we freeze the memory

Attention + attention + DQo8L2Jsb2NrcXVvdGU + DQo8aDQgaWQ9 "it seems that the pace is getting faster and faster. In the next section, we will learn the pointer, so we will have a clear understanding of c. It is also great for us to finish learning this item "> it seems that the pace is getting faster and faster, in the next section, we will learn the pointer, so that we will have a clear understanding of C. It is also of great benefit to ourselves to finish learning this item early!

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.