Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > C/C++
You last visited: Today at 10:40

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



[GUIDE C] Pointers

Discussion on [GUIDE C] Pointers within the C/C++ forum part of the Coders Den category.

Reply
 
Old   #1
 
GunSnow's Avatar
 
elite*gold: 0
Join Date: Mar 2013
Posts: 34
Received Thanks: 16
[GUIDE C] Pointers

Hi all,

today I decided to write this guide to deal with a very difficult topic for many: the pointers.
But without further ado, we start.

First of all, let's start with doing a little 'theory.
As you all know, its a variable declaration is organized so as to have its reference and its value. The reference of a variable is unique and represents the memory location in which it resides, so you can find it when it is invoked. The value of the variable, instead, can vary over time and represents the content of that memory cell where it resides.

In summary, then, the variable is composed of:
- Left Value (LV) of the variable reference or memory address
- Right Value (RV): contents of that cell
These value are governed by specific details. An example is the assignment: a variable assignment in the meaning of the same changes depending on the position with respect to the symbol "=".

I bring you an example so you can better understand what was said:
PHP Code:
.
.
.
int a; / * a is the name of a variable of type int * /
.
.
.
1; / * Insert into the cell memory location identified by a value of 1then we haveLV (a) <- * /
+3; / * Insert into the cell of a memory location identified by the value of a 3. This meansLV (a) <- RV (a) + * / 
This part is important, so before going any further, make sure you have assimilated the concept.
Without this parenthesis on the organization of memory variables, pass the object itself of the guide: the pointer.

The pointer is a variable that is not very different from other commonly used. Its uniqueness is that it contains the memory address of another variable, or its Left Value.
In practice, we can write this:
PHP Code:
int a 12[10];
int ptr;

ptr = &a; / LV * (ptr) <- LV (a), ptr now points to a * /
= * ptr; / * LV (b) <- RV (a), b is equal to the value of the variable pointed right * /
ptr 0; / * RV (a) <- * /
ptr = & [0] / * LV (a) <- LV (z), ptr now points to z [0] * / 
This simple example helps us to understand many things.
- Int a = 1: is the normal declaration of a variable of type integer, the identifier
- Int * ptr: is the declaration of a variable of type "pointer" (in this case to an integer). The syntax, expressed by the BNF, which defines the declaration of a pointer is: <type> * <exp>;
- B = * ptr: the unary operator * is called indirection or deferenzazione (indirection or deferencing). In a statement specifies that what follows will be a variable pointer to the declared type. In an expression, applied to a pointer variable, allows you to access the variable pointed to by the pointer.
- Ptr = & a: is assigned to the Value of ptr Right of Left Value of a. We infer, therefore, that the unary "&" returns the value of the left variable is applied. In this case, it is said that ptr points to a.

The pointers are very useful in programming, especially in the following situations:
- Exchange of Function Parameters
- Construction of Array and more complex data structures (an example: the list)
- Dynamic memory allocation


Another important point to be clarified is how pointers can return useful as arguments to functions. Since the C function arguments are passed by value all, there are some problems difficult to solve without the use of pointers. We put our attention on this feature:
PHP Code:
void swap (int xint y) / * WRONG * /
{
*** 
int tmp;

*** 
tmp x;
*** 
y;
*** 
tmp;

This function takes as parameters two integers and exchange values. All would be correct, except that the exchange is effective only within the function! This is because of the pass by value: the two integers passed to the function are "copies" of the real variables passed as arguments. Then, at the end of the function, they will no longer be visible from the outside.
The correct function makes use of the pointers:
PHP Code:
void swap (int ptrXint PTRY) / * CORRECT * /
{
*** 
int tmp;

*** 
tmp = * ptrX;
*** * = * 
ptrX PTRY;
*** * 
PTRY tmp;

The function, built in this way, is put in condition to be able to modify the original variables, not by operating more of the copies.



I hope I have been clear enough in dealing with the subject and the exposition of concepts. For any additional information, criticism and advice write below using tones quiet and calm.
The next guide treat pointers, the carriers and the manner in which they are closely connected.

Greetings!
GunSnow is offline  
Old 03/27/2013, 07:43   #2
 
elite*gold: 42
Join Date: Jun 2008
Posts: 5,425
Received Thanks: 1,888
Code:
int a; / * a is the name of a variable of type int * /
Stopped reading there.
MoepMeep is offline  
Thanks
1 User
Old 03/27/2013, 12:06   #3
 
elite*gold: 0
Join Date: Nov 2009
Posts: 343
Received Thanks: 45
Wow danke, sehr guter Guide! Jetz habe ich das endlich mit den Pointer verstanden! *Daumen hoch*
Mach weiter so, ich hoffe, da kommen noch eine Guides in diesem Format!
Cheers!
yihaaa is offline  
Old 03/29/2013, 13:02   #4
 
Lazeboy's Avatar
 
elite*gold: 0
Join Date: Jun 2008
Posts: 451
Received Thanks: 410
you forget this lol:

Code:
int ******************ptr;
int a = 200;
int b = 0;
    *****************  ptr = &a;
    b   =  ******************ptr; //b = 200
Lazeboy is offline  
Reply


Similar Threads Similar Threads
[GUIDE]How to find pointers in CE6.1
07/30/2016 - Cabal Guides & Templates - 41 Replies
Ok, since I noticed a lot of questions about why adresses keep changing or how to find the base adress for an adress you found, i will poast this very short guide. Things needed: - Cheat Engine 6.1 or 6.2 (i still use 6.1) --> check link at the bottom of this guide - At least some form of brains Use of pointers: You won't have to search an adress every time you start Cabal Online again. BEFORE YOU ASK QUESTIONS, READ THIS GUIDE ENTIRELY!
Pointers please?
11/26/2011 - Mabinogi - 22 Replies
I've gotten interested in how mabi's world is laid out. So I got Pake so I can play around with teleportations :3 Can anybody give me pointers about how to find an area's warp-code? I'm guessing it has something to do with map boundaries, or examining other warp methods. I'll take a hint and try to figure it out myself, if you'd be so kind as to give me a pointer ^^
About Pointers
01/01/2010 - Cabal Online - 1 Replies
Can someone explain briefly how to make ur do pointers? thanks and happy new year!
Pointers with CE, help
01/15/2009 - General Coding - 0 Replies
Hello! Guys im having problems when I try to search for a pointer of a dynamic address using CE 5.4. Always when I press "Find out what writes to this address" or similar options the game just will crash. I'm not able to go further with this problem. If anyone knows how to fix this problem, or knows another way to do it give me a tip and i'll try to find it and learn it. Thanks,



All times are GMT +1. The time now is 10:40.


Powered by vBulletin®
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2025 elitepvpers All Rights Reserved.