Pointer introduction, mouse pointer

Source: Internet
Author: User

Pointer introduction, mouse pointer

Pointer:

1. Declare a pointer of the int type and assign a value.

 

2. assign values directly in the Declaration.

 

Iii. NULL pointer

 

4. Floating pointer wild pointer:

 

A floating pointer is essentially a variable of the pointer type [for example, int * p] and has no value assignment. If no initial value is assigned, use this pointer to modify it, for example, * p = 100 ]. This pointer points to an unknown address. The modification is also made. If the address is another process. After modification, the system becomes unstable. This kind of unreliable modification behavior is terrible. It is like Lu Bo opened his home to Cao, and when Cao came in, he randomly modified the data of his family, sets whether to survive to false. in the dos operating system, such modifications are acceptable. However, as more and more hackers want to modify the data of the operating system, it is equivalent to opening up my own operating system. You have run some things, this collapsed my operating system. So the later operating system was like this:

 

That is, with the increasing number of such terrible acts, the law later found that if you cross-border access, we believe that you are guilty of illegal entry. There is a process that constantly detects. If a user process has unauthorized access, it will immediately clear the process from the memory to ensure the stability of the operating system. So now we can rest assured to do this case demonstration of hanging pointers, but our process encountered problems and was forced to stop. This is acceptable.

5. pointer compatibility

Run the following code:

# Include <iostream> void function1 (void); void function2 (void); void function3 (void); void function4 (void); void function5 (void); int main () {function5 (); return 0;}/** declares an int pointer and then assigns a value. */Void function1 (void) {int I = 10; printf ("the value of I before modification is % d \ n", I); int * p; // define a pointer variable that executes the int type as p. p = & I; // assign the I address to p. * P = 100; // * p indicates that the content in p is accessed and extracted based on the int type. // * P is equivalent to I because I is assigned to this file. So I = 100. // Therefore, * p = 100 is essentially a value assignment statement that changes the I value to 100. printf ("the modified I value is: % d \ n", I);}/** directly assigned a value in the Declaration. */Void function2 (void) {int I = 10; int * p = & I; printf ("I value: % d \ n", * p );} /** NULL pointer */void function3 (void) {// int B = NULL; // printf ("B value: % d \ n", B ); int * p = NULL; // This is the legendary NULL pointer. It is common to report an error in java. // This is because when an object is created, no initial value is given, leading to the exception printf ("pointer p value: % d, % p, % x", p );} /** floating pointer, wild pointer: in fact, it is similar to function1 () content, that is, to declare a pointer type variable, but not assign a value. This compilation is successful, but an error is reported during running. Visual studio c ++ does not support compilation. This is because. No one knows what memory units p points. And the 100 value is assigned to it without your knowledge, which will be extremely insecure. */Void function4 (void) {int * p; * p = 100; printf ("the value of the address pointed by the floating pointer is % d \ n", * p );} /** pointer compatibility */void function5 (void) {// previously mentioned in the first case that a pointer variable of the int type was declared, it is because there are also various types of pointer variables. // For example: char * pc; int array [10]; int * p = array; // I am a bit blind now... Double * pd; // That is what we said. First find the corresponding element and then extract the content in the pc according to the char type // follow the double type, take the value in pd // so for pointers, their sizes are the same: printf ("the size of the pointer variable pc: % d \ n pointer Variable p size % d \ n pointer variable pd size % d \ n ", sizeof (pc), sizeof (p), sizeof (pd )); // [view the running result diagram], you will find that in this machine, all pointer variables are 8, indicating that this is a 64-bit operating system. // If these values are 4, it indicates that this is a 32-bit operating system. Therefore, the value of pointer variable is related to the operating system. // Therefore, You need to specify a type for the object to be pointed to during the value, so that you can extract the element according to the appropriate type. // In order to continue, comment out the comment here, which is critical! Be sure to try it. // if it is int * p1; char c; // p1 = & c; //, the following error will be reported: cannot convert 'Char * 'to 'int *' in assignment int * p2; unsigned int i1; // p1 = & i1; // This compilation is still strict, that is, it won't work. This is allowed in. // [Error] invalid conversion from 'unsigned int * 'to 'int *' [-fpermissive] // It is allowed to declare a pointer pointing to a null type.. Void * pv; pv = & c; pv = & i1; // This is the result of compilation. // P1 = pv; // [Error] invalid conversion from 'unsigned int * 'to 'int *' [-fpermissive]}

 

The above is the case of main. cpp.

 

The following is the case of main. c:

 

#include <iostream>int main() {    int *p;    unsigned int i;    //p=&i;     //[Error] invalid conversion from 'unsigned int*' to 'int*' [-fpermissive]    int ii;    p=&ii;        void *p1;    p1 = p;        char *pc;    //pc = p1;    //[Error] invalid conversion from 'void*' to 'char*' [-fpermissive]    return 0;}

 

 

 

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.