Use Insecure code operation pointer in C #

Source: Internet
Author: User
  1. Using system;
  2. Using system. Collections. Generic;
  3. Using system. text;
  4. Insecure namespace code
  5. {
  6. Unsafe class Program
  7. {
  8. Static void main (string [] ARGs)
  9. {
  10. Int x = 10;
  11. // Declare two integer pointers
  12. Int * PX, Py;
  13. // Assign the X address to the integer pointer PX
  14. Px = & X;
  15. // The path where the py pointer and PX are stored
  16. Py = px;
  17. // Change the value of the address pointed to by pointer Px to 20 (that is, X)
  18. * PX = 20;
  19. // Convert the address value to an integer
  20. Uint y = (uint) Px;
  21. Console. writeline ("pointer to integer:" + y );
  22. // Assign the integer address to the pointer
  23. Int * Pd = (int *) y;
  24. Console. writeline ("finding the value in the address through an integer address:" + * PD );
  25. Console. writeline (X );
  26. Console. Readline ();
  27. }
  28. }
  29. }
  30. /**
  31. * The unsafe keyword can be used to modify methods, classes, and member variables to notify the compiler system to use unsafe code.
  32. & The symbol is the address-taking operator, * is the content of the address, that is, the value.
  33. */

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.