473,769 Members | 1,694 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

What can pointers do that other things can't do?

I am trying to put my learning effort into the most useful things.
What do pointers do that other things can't?

Michael Bell

--
Dec 2 '07
12 2570
On 2007-12-03 13:23, Michael Bell wrote:
In message <cd************ *************** *******@s8g2000 prg.googlegrou
ps.com>
Salt_Peter <pj*****@yahoo. comwrote:
>___
All this to state:
a) Use a reference instead of a pointer whenever you can. Its the best
insecticide i know.
b) If you must use a pointer, always initialize it (if you can't give
it a valid address yet - then null it)

This is jargon I don't know. Does "reseat" mean to point a pointer at
some other address? That seems to the meaning of
Reseat means to make it refer to something else. A reference can only
refer to one thing, and you have to decide what that is when you create
it, with a pointer on the other hand you can change what it points to.
>int m(77);
p = &m; // reseated pointer


What exactly is going on here?
m is created and given the value 77, then the address of m is taken and
is stored in p. This means that p will now point to m.
>int j;
j has been declared. No problems about that!
>int& ref = j; // ref is permanently bound
What has happened here?
When you create the reference ref you say that it refers to j. After
this you can think of ref as an alias for j, ref and j are now two
different names for the same thing.
>// ref = m; // error
ref = 55; // ok, j is now set to 55

Sorry, I just don't understand.
Since ref and j are the same thing, setting the value of ref is the same
as setting the value of j.

How about this analogy: there is this guy named Bob, when someone talks
about Bob they mean him. However Bob has a son, and when he talks about
Bob he call him "dad". In this case dad is a reference to Bob, they both
refer to the same thing.

Bob is the boss at a company, and when his employees talk about the boss
they talk about him, but if Bob should be sacked and a new boss hired
the employees would still talk about the boss, but no longer about Bob.
In this case "the boss" is a pointer, it refers to a person but
indirectly and who it refers to can thus be changed.

--
Erik Wikström
Dec 4 '07 #11
On Dec 3, 11:15 am, Matthias Buelow <m...@incubus.d ewrote:
Michael Bell wrote:
Thank you for this. It has told me something of value: that it is
worth my time and effort to learn about pointers.

If it's worth wasting people's time on Usenet, it's certainly worth
learning about yourself.
Michael, ignore the miserable ones and Usenet will be a wonderful place
Dec 4 '07 #12
Diego Martins wrote:
We know most of times the best approach is being kind.
The kind of arrogance ("tell me that it is worth my time and effort")
the OP has displayed does not warrant a kind answer.
Dec 6 '07 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
411
by: Peter Mount | last post by:
Hello Are there any good online tutorials that explain pointers in ANSI C? I've covered pointers in my course but I'm just having trouble "getting it to sink in". Thanks Peter Mount info@petermount.au.com
19
1630
by: s.subbarayan | last post by:
Dear all, I had this following doubt,while java is able to carryon with out pointers why C language cant be modified to remove pointer?Hows java able to do this with out pointers? I jus plead sorry to those who advice me to post it to java people because I have already done it. Jus want to know alternatives to pointers which can be used with C.While pointers provide flexibility most bugs are with respect to pointers.So will it not be...
20
1654
by: Bill Potter | last post by:
I am a learning programmer in C and i want to know why some one would use pointers instead of going direct!
51
4557
by: jacob navia | last post by:
I would like to add at the beginning of the C tutorial I am writing a short blurb about what "types" are. I came up with the following text. Please can you comment? Did I miss something? Is there something wrong in there? -------------------------------------------------------------------- Types A type is a definition for a sequence of storage bits. It gives the meaning of the data stored in memory. If we say that the object a is an
2
2922
by: Steven T. Hatton | last post by:
It's my understanding that intrusive pointers are frowned upon. For example this is from the boost::intrusive_ptr documentation: "As a general rule, if it isn't obvious whether intrusive_ptr better fits your needs than shared_ptr, try a shared_ptr-based design first." This tells me that intrusive pointers are faster and leaner than any of the other alternative other than raw pointers. http://www.boost.org/libs/smart_ptr/smarttests.htm ...
54
12019
by: Boris | last post by:
I had a 3 hours meeting today with some fellow programmers that are partly not convinced about using smart pointers in C++. Their main concern is a possible performance impact. I've been explaining the advantages of smart pointers endlessly (which are currently used in all our C++ software; we use the Boost smart pointers) as I'm seriously concerned that there is a shift to raw pointers. We are not developing system software but rather...
69
3207
by: Yee.Chuang | last post by:
When I began to learn C, My teacher told me that pointer is the most difficult part of C, it makes me afraid of it. After finishing C program class, I found that all the code I wrote in C contains little pointers, obviously I avoid using them. A few days ago when I was reading a book about programming, I was told that pointers are the very essence of C language, if I couldn't use it well, I'm a bad programmer, it's a big shock. So now I'm...
16
3448
by: John Doe | last post by:
Hi, I wrote a small class to enumerate available networks on a smartphone : class CNetwork { public: CNetwork() {}; CNetwork(CString& netName, GUID netguid): _netname(netName), _netguid(netguid) {}
49
2436
by: Zach | last post by:
After having taken a looong break from VB (last used 6.0), I started getting back into programming again, this time with VS 2005. I began reading up on VB.NET from various sources (books, internet, etc.) and found out about the CLR and how all of the .NET languages access it, the major difference being the syntax and structure of the individual languages. What I'm wondering, since VB.NET is obviously easier to learn/use than C#.NET and...
0
9415
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10032
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9848
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8860
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7392
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6661
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3947
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 we have to send another system
2
3551
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2810
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.