Android for JNI (ii) data types in--c language, output, input functions and operation memory address, memory modifier
When we finish writing Hello World, we can enter the gate of C, and today we will talk about some basic data types, functions within the
Let's take a look at a picture that spreads long ago.
I. Various data types introduction to integral type
Shaping includes short integer, Shaping, and long-shaping.
Short shaping
Short a=1;
Plastic
Typically 4 bytes (32 bits), the highest bit represents the symbol, 0 is a positive number, 1 is negative, the value range is -2147483648~2147483647, in memory the order of storage is status before, high, for example, 0x12345678 in memory storage as follows:
Address: 0x0012ff78 0x0012ff79 0x0012ff7a 0x0012ff7b
Data: 78 56 34 12
Definition: Using the INT keyword, for example:
int a=6;
Long Plastic
Long a=10;
Floating point Type
Floating-point types include single-and double-precision types.
Single-precision
Floating-point type, also known as the real type, is called the single precision. Typically takes 4 bytes (32 bits),
float a=4.5;
Address: 0x0012ff78 0x0012ff79 0x0012ff7a 0x0012ff7b
Data: 00 00 90 40
Double-precision Type
Typically 8 bytes (64 bits)
Double a=4.5;
Address: 0x0012ff78 0x0012ff79 0x0012ff7a 0x0012ff7b 0x0012ff7c 0x0012ff7d 0x0012ff7e 0x0012ff7f
Data: 00 00 00 00 00 00 12 40
Character type
In a variety of different systems, the character type takes up one byte (8 bits). Defined as follows:
Char c= ' a ';
You can also assign a value to the ASCII code that corresponds to the character, as follows:
Char c=97;
In fact, we can use a string of code to explain the above meaning
#include <stdio.h>#include <stdlib.h>Main () {//Basic data type: Char int float long short double signed unsigned inti =3;CharA =' C ';format specifier for//int%d printf("I has a value of%d", i);format specifier for//char printf("A has a value of%c", a); System"Pasue");//General outputSystem"Universal Output%d",sizeof( Short));//char int float long SHORTD usage is similar to Java //We mention signed unsigned //signed: Signed unsigned unsigned //Give an example signed inti =3;//Plus/minus unsigned intI2 =3;//No plus or minus //byte length char 1 int 4 float 4 long 4 short 2 double 8}
is not clear, but we also come from Java, these can basically take a stroke, we look at the C function
Two. Output function
Here, let's brush up on the output functions mentioned above.
- %d-int
- %ld–long int
- %lld-long Long
- %hd– Short-integer
- %c-char
- %f-float
- %lf–double
- %u– unsigned number
- %x– hexadecimal output int or long int or short int
- %o-eight binary output
%s– string
Int Len;
- SCANF ("%d", &len);
Because this is not in Java, so here is still to mention the
//C的数组[]要写在后面 ,而且这个 数组的长度为 8,因为他有一个结束符 \0 charstr [] = {‘a‘,‘n‘,‘d‘,‘r‘,‘o‘,‘i‘,‘d‘charstr"可以输入"; //9个字节长度
Three. Input function
Input function Everyone is not unfamiliar, also in Java, Java code is generally like this
import java.io.*;publicclass Test1 {/** * @param args * @throws IOException */publicstaticvoidmainthrows IOException { new BufferedReader(new InputStreamReader(System.in)); String str = stdin.readLine(); System.out.println(str);}}
This allows you to enter something in the console, but C is much simpler, and it also mentions a function scanf ("%d", &len); Let's see how it's done.
#include <stdio.h> #include <stdlib.h> //输入函数 main(){ printf("请输入你的年龄:"); //定义一个变量 int age ; //设置输入的类型为int scanf("%d",&age); printf("你的年龄为:%d\n",age); system("pause"); }
So let's run a little bit:
That's OK.
Four. Memory address
This piece of memory, C can be directly to operate, which is his advantage, but also he is more difficult piece, we have to grind a good grind, memory address is the address of memory, memory so the data are obtained through the address, like Findviewbyid, Let's look at an example
#include <stdio.h> #include <stdlib.h> main(){ int i ; //当i声明的时候,内存中开辟一个空间,四个字节,无值,分配一个地址 5; //给地址一个值 printf("%d\n"//当我们要输出这个i的时候其实是通过地址拿到这个5的 //获取内存地址 printf("%#x",&i); //让窗口停留 int age ; scanf("%d",&age);}
We use this line of code to get the value of I and the address of I, the printed result
For a more figurative explanation, for example, the computer system has 32 and 64-bit distinction, the 32-bit system is the largest support for 4G memory, because the 32-bit system memory bus length is 32, that is, can be allocated to memory as the address of the number 2
Five. Memory modifier
Modify memory, like playing a game, your blood volume is 100, actually is in memory define a variable, such as int blood = 100, this blood in memory open a space, assign 100, and then do other operations, we write a small example
#include <stdio.h>#include <stdlib.h>Main () {//Time is 60s pass intTime = -;intI//Print the address of I printf("% #x \ n", &i); for(i = time;i>=0; i--) {printf("Time remaining is%d\n", i);//sleep, achieve diminishing effectSleep +); }//Let the window stay intAge;scanf("%d", &age); }
Logic should be able to understand, we define an I, and then get his memory address, and then let him do a countdown to the same operation, which simulates the game, such as a minute clearance within the game, we modify the memory of I, to achieve the effect of memory modifier
Then we can download cheat Engine, this is the memory modifier, and the principle of the eight-door artifact is similar
Go online to find it, the specific usage, we can Baidu
When we froze the memory,
You have reached the effect of modifying the game, never to 0, also will not die, here is just a principle of elaboration Oh!
It seems that the rhythm more and more quickly, the next section we learn the pointer, so that will have a clear understanding of C, early to finish this piece of learning, for oneself is also a great advantage!
Android for JNI (ii) data types in--c language, output, input functions and operation memory address, memory modifier