473,466 Members | 1,439 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

pointer

1 New Member
i want to full detail of pointer concept.
means how can i access pointer in my programs?
why pointer is always consume 2 bytes? and what is the main concept behind the double pointer?
Sep 23 '06 #1
2 2744
Banfa
9,065 Recognized Expert Moderator Expert
i want to full detail of pointer concept.
means how can i access pointer in my programs?
why pointer is always consume 2 bytes? and what is the main concept behind the double pointer?
A pointer is a variable that holds the address of a memory location. This may or may not be the address of another variable or a piece of allocated memory. often specify what type of thing it is that the pointer is pointing to, however it is possible to specify a pointer that points at anything.

A pointer is not always 2 bytes. In fact on most of the systems I have used pointers have been 4 bytes, however I have used a system where pointers where either 2 or 4 bytes depending on how they were declared. The size of a pointer is not specified by C it is platform (machine and compiler) dependent.

Pointers are useful anywhere where you wish to pass a reference to an object, they are also integral to using dynamically allocated memory because malloc (or new) returns a pointer to the allocated memory.

If by double pointer you mean a pointer to pointer, this is useful anywhere where you want to reference a pointer.
Sep 23 '06 #2
gasfusion
59 New Member
let's say you have the following:
int x=54;
int *ptr = NULL;

ptr = &x; // point to the address in the memory where x is stored (i.e. 1000)
cout << *ptr // This will ouput whatever is at the address (1000): 54

to incrementing a pointer works the same as incrementing an integer, you just have to make sure you're incrementing the address the pointer is pointing to:
ptr++;

you can change whatever point is pointing to without changing the variable x that we have above. We know that ptr is pointing to the address of 54 so to change that we do this:
*ptr = 23;

This'll change x to 23.
Here is my quick IP testing function that's using pointers, just to give you an example. It's a shitty code but it's just to show you how the pointers operate:
Expand|Select|Wrap|Line Numbers
  1.         char* ptr = NULL; // main pointer
  2.         int cnt = 0;  //counting the number of dots
  3.         ptr = tAddr;  // assigning initial IP to the pointer
  4.         char tptr[20];  //storage array for checking numbers between dots
  5.         int i= 0;  // storage array integer
  6.         while (*ptr != '\0') {  // while not the end of the IP
  7.             if ((*ptr != '.') && (cnt < 4)) {  //if pointer doesn't equal ".", must be a num
  8.                 tptr[i] = *ptr;  // store the number in the store array
  9.                 i++;  // go to the next cell in array                
  10.             } else if (*ptr == '.') {  // if pointer is a "."
  11.                 i -= 1; // decrement my i because of the "." occurence
  12.                 if (atoi((char*)(tptr)) <= 255) { //check the range of your number
  13.                     int a=0; 
  14.                     for(a=0;a<=i;a++)  // empty storage array for the next number
  15.                         tptr[a] = NULL;
  16.                     i = 0;  // set i back to 0 so we start at the beginning of our storage array
  17.                 } else { // if our number isn't in range
  18.                     int a=0;
  19.                     for(a=0;a<=i;a++)  // empty the array again
  20.                         tptr[a] = NULL;
  21.                     cout << "not in range"; // ouput error
  22.                     i=0; 
  23.                 }
  24.                 cnt++; // increment dot counter
  25.             }
  26.                 ptr++; // increment the poiner
  27.         }
  28.  
Sep 24 '06 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Carsten Spieß | last post by:
Hello all, i have a problem with a template constructor I reduced my code to the following (compiled with gcc 2.7.2) to show my problem: // a base class class Base{}; // two derived...
110
by: Mr A | last post by:
Hi! I've been thinking about passing parameteras using references instead of pointers in order to emphasize that the parameter must be an object. Exemple: void func(Objec& object); //object...
3
by: Bruno van Dooren | last post by:
Hi All, i have some (3) different weird pointer problems that have me stumped. i suspect that the compiler behavior is correct because gcc shows the same results. ...
35
by: tuko | last post by:
Hello kind people. Can someone explain please the following code? /* Create Storage Space For The Texture */ AUX_RGBImageRec *TextureImage; /* Line 1*/ /* Set The Pointer To NULL...
16
by: junky_fellow | last post by:
According to Section A6.6 Pointers and Integers (k & R) " A pointer to one type may be converted to a pointer to another type. The resulting pointer may cause addressing exceptions if the...
204
by: Alexei A. Frounze | last post by:
Hi all, I have a question regarding the gcc behavior (gcc version 3.3.4). On the following test program it emits a warning: #include <stdio.h> int aInt2 = {0,1,2,4,9,16}; int aInt3 =...
16
by: aegis | last post by:
Given the following: int a = 10; int *p; void *p1; unsigned char *p2; p = &a;
23
by: bluejack | last post by:
Ahoy... before I go off scouring particular platforms for specialized answers, I thought I would see if there is a portable C answer to this question: I want a function pointer that, when...
69
by: fieldfallow | last post by:
Hello all, Before stating my question, I should mention that I'm fairly new to C. Now, I attempted a small demo that prints out the values of C's numeric types, both uninitialised and after...
8
by: Martin Jørgensen | last post by:
Hi, "C primer plus" p.382: Suppose we have this declaration: int (*pa); int ar1; int ar2; int **p2;
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.