473,378 Members | 1,309 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

How many times a pointer can point to another pointer>

visualbasic1111
Hi All, I want to know whether how how many time a pointer can point to another pointer, in the way

P1->P2->P3->P4..................

up to where this link can proceed ans is valid in C or C++
Mar 30 '10 #1

✓ answered by jkmyoung

It is only limited by the memory you have. You could even have circular pointers, creating an infinite loop!
P1 -> P2 -> P3 -> P4 -> P1 -> ....

6 1849
jkmyoung
2,057 Expert 2GB
It is only limited by the memory you have. You could even have circular pointers, creating an infinite loop!
P1 -> P2 -> P3 -> P4 -> P1 -> ....
Mar 30 '10 #2
weaknessforcats
9,208 Expert Mod 8TB
This is a very poor coding techinque. It is called "spaghetti code". By using it you create threads of variables p1->p2->p3->p4 where if aby of the pointers are zero, you program crashes. Where if any of the pointers are members of structs you have exposed the name of the member and have destryed your ability to redesign the struct without trashing trhe entire program. Where the values of the objects pointed at can be changed willy-nilly anywhere in the code so you have to debug 75,000 functions instead of the one that's doing it.

etc...

Research encapsulation for ways to avoid this.
Mar 30 '10 #3
jkmyoung
2,057 Expert 2GB
Are you looking for ways to obfuscate your code, or are you really looking for some sort of Linked List Implementation?
Mar 30 '10 #4
thanks 4reply but I hear from my friend who is an mca student, that the limit in this way is upto 14 pointers measns
p1->p2->p3->.....................->p13->p14 then I was a bit confused whether what is the limit when a pointer can point to another pointer. Thank You All.
Mar 31 '10 #5
Banfa
9,065 Expert Mod 8TB
try this program, compiles and runs for me
Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. struct Tester
  6. {
  7.     int value;
  8.     Tester* next;
  9. };
  10.  
  11. static const int LIMIT = 100;
  12.  
  13. int main()
  14. {
  15.     Tester top = {0, NULL};
  16.     Tester* current = &top;
  17.  
  18.     for(int ix = 0; ix<LIMIT; ix++)
  19.     {
  20.         current->next = new Tester;
  21.         if (current->next == NULL)
  22.         {
  23.             break;
  24.         }
  25.  
  26.         current = current->next;
  27.         current->value = ix+1;
  28.         current->next = NULL;
  29.     }
  30.  
  31.     cout << top.next->next->next->next->next->next->next->next->next->next->
  32.     next->next->next->next->next->next->next->next->next->next->
  33.     next->next->next->next->next->next->next->next->next->next->
  34.     next->next->next->next->next->next->next->next->next->next->
  35.     next->next->next->next->next->next->next->next->next->next->
  36.     next->next->next->next->next->next->next->next->next->next->
  37.     next->next->next->next->next->next->next->next->next->next->
  38.     next->next->next->next->next->next->next->next->next->next->
  39.     next->next->next->next->next->next->next->next->next->next->
  40.     next->next->next->next->next->next->next->next->next->next->value
  41.     << endl;
  42. }
Of course that could just be an extension on the compiler I am using, however the C++ specification makes no mention of a limit of the number of times you may de-reference a pointer, and indeed why should it, its an easy enough operation to do.
Mar 31 '10 #6
Thank You Sir I have got sufficent answer for my question. Thanks
Apr 2 '10 #7

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

Similar topics

5
by: John Fouhy | last post by:
Can someone explain these differences? >>> from math import pi >>> pi 3.1415926535897931 >>> type(pi) <type 'float'> >>> repr(pi) '3.1415926535897931' >>> str(pi)
0
by: It's me | last post by:
I've built a Python application using PythonCard 1.9 and Python 2.3 running under Windows XP. Everything works except that when I use the keyboard instead of the mouse to do certain operations in...
1
by: Jakob Bieling | last post by:
Hi, in a post from 1995 ('why pass references?') in this group, Steve Clamage said reading the value of an indeterminate pointer (no dereferencing taking place) is undefined behavior. While I am...
822
by: Turamnvia Suouriviaskimatta | last post by:
I 'm following various posting in "comp.lang.ada, comp.lang.c++ , comp.realtime, comp.software-eng" groups regarding selection of a programming language of C, C++ or Ada for safety critical...
3
by: Alvey Sidecast | last post by:
Win XP, Access 02: I've got a largish table with three (relevant) fields; Item, PIN & Incid. What I'd like to accomplish in one SQL query (I can do it in a couple but it's ugly. Also,the app...
2
by: beetle | last post by:
Hello, I'm storing data in several different binary tree's. The root node is located in a struct containing general data about the tree. struct lnode { char *fname; int nentry;
5
by: mkaushik | last post by:
Hi everyone, Im just starting out with C++, and am curious to know how "delete <pointer>", knows about the number of memory locations to free. I read somewhere that delete frees up space...
232
by: robert maas, see http://tinyurl.com/uh3t | last post by:
I'm working on examples of programming in several languages, all (except PHP) running under CGI so that I can show both the source files and the actually running of the examples online. The first...
17
by: Jason Doucette | last post by:
I am converting a C-style unit into a C++ class. I have an implementation function that was defined in the .cpp file (so it was hidden from the interface that exists in the .h file). It uses a...
2
by: Hvid Hat | last post by:
Hi Is it somehow possible to call Graphics.DrawLine with List<Point>? Does it only take Point arrays? If so, how can I (easily) convert my List<Point> to a Point array?
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...

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.