"C + + Institute" (3) two-dimensional array/Two-point lookup method/pointer/module injection

Source: Internet
Author: User

1. Two-dimensional array

A two-dimensional array can be used as a one-dimensional array, and each element is a one-dimensional array.

#include <stdio.h> #include <stdlib.h>void main () {    int a[3][4] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; for    (int i = 0; i < 3; i++)    {        for (int j = 0; J < 4; j + +)        {            printf ("%d,%d,%d,%x,%x   ", A[i][j], * (A[i] + j), * (&a[i][j]), &a I [j],a[i]+j);        }        printf ("\ n");    }    A[x], which represents the first address of an element in line X, the hand address of this array in a row,    printf ("\n\na[0]=%x,a[1]=%x,a[2]=%x", A[0], a[1], a[2]);    System ("Pause");}  

2. Two-point lookup method

While/for two ways to achieve

#define _crt_secure_no_warnings#include <stdio.h> #include <stdlib.h>void showarray (int a[], int n) {for ( int i = 0; I < n; i++) {printf ("%d,", A[i]);} printf ("\ n");} void Paixu (int a[], int n) {for (int i = 0; i < n-1; i++) {for (int j = 0; J < n-1-I; k + +) {if (a[j]>a[j+1]) {i NT TEMP = A[j];a[j] = a[j + 1];a[j + 1] = temp;}}} Num is the data to be looked up, returning the array subscript int searchfor (int a[], int n, int num) {for (int tou = 0, Wei = n-1, Zhong = (tou + wei)/2; Tou &lt ; = Wei; zhong= (Tou+wei)/2) {printf ("\ n start looking for%d,%d,%d", Tou, Wei, Zhong), if (a[zhong] = = num) {return zhong;} else if (a[zhong]>num) {wei = zhong-1;} Else{tou = zhong + 1;}}} int searchwhile (int a[], int n, int num) {int tou = 0;int Wei = n-1;int zhong = (tou + wei)/2;while (Tou <= wei) {pri NTF ("\ n start looking for%d,%d,%d", Tou, Wei, Zhong), if (a[zhong] = = num) {return zhong;} else if (a[zhong]>num) {Wei = Zhong-1;zhong = (tou + wei)/2;} Else{tou = zhong + 1;zhong = (tou + wei)/2;}}} void Main () {int a[50] = {0};time_t ts;srand ((unsigned int) time (&ts));//random number seed for (int i = 0; i <; i++) {A[i] = rand ()% 100;//printf ("%d,", A[i]);} Paixu (A, 50); Showarray (A, +), int num;printf ("plesae input your Find num:"), scanf ("%d", &num);//scan data receive input//int ret = Searchfor (A, 5 0, num); int ret = Searchwhile (A, A, num), if (ret = =-1) {printf ("not find\n");} else{printf ("Find [%d]\n", A[ret]);} System ("Pause");}



3. Pointers, function pointers

normal pointer, variable address, function pointers, The function address.

void (*P1) () = (void (*) ()) 0x2a1118;//function address 0x2a1118
P1 ();

#include <stdio.h> #include <stdlib.h>int add (int a, int b) {return a + B;} void Main () {int n = 100;int *p = &n;*p = 50;printf ("%d\n", n), int (*PF) (int, int);//function pointer pf = add;printf ("%d\n", pf (3, 5 ); System ("Pause");}

second-level pointers;

#include <stdio.h> #include <stdlib.h>char a = ' a '; char b = ' B '; char c = ' C '; void change (char **pp) {    *pp = &b;    **pp = ' D ';} void Main () {    char *p = &a;    printf ("My rank is: [%c]\n", *p);    Change (&p);    printf ("My rank is: [%c]\n", *p);    


4. Module injection

DllInject.exe Tools

_declspec (dllexport) void Go ()//export as DLL module;

Target procedure;

#include <stdio.h> #include <stdlib.h> #include <windows.h>char a = ' a '; char b = ' B '; char c = ' C '; void Mai N () {char *p = Null;p = &a;printf ("p=%x,&a=%x,&b=%x,&c=%x\n", p, &a, &b, &c); while (1) {printf ("My rank is: [%c]\n", *p); Sleep (10000);//10s}}

Plug-in module;

_declspec (dllexport) void Go ()//export to DLL module; {Char **pp = (char * *) 0x288000;//get p address *pp = (char *) 0x288002;//level C address}




"C + + Institute" (3) two-dimensional array/Two-point lookup method/pointer/module injection

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.