954,483 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Pointers,vars,etc

Im new to c++, Ive been plowing through books,web,etc. Many of the things im learning seems redundant but being new as I am I figure that it stems from lack of knowledge. Now finally my questions...Whats the significance of using pointers to reference variables when i could just flat out write[ int k =3;] for example. Question 2 why is so much emphasize on space allocation? My last question is are there things I should learn before attempting to learn c++? ps have attachements I made cant tell the which is better.

Attachments structs.cpp (0.54KB) difference.cpp (0.31KB)
pharoah85
Newbie Poster
11 posts since Oct 2010
Reputation Points: 10
Solved Threads: 0
 

hm... interesting...

nikaso
Newbie Poster
7 posts since Mar 2010
Reputation Points: 10
Solved Threads: 2
 
Fbody
Posting Maven
2,930 posts since Oct 2009
Reputation Points: 833
Solved Threads: 393
 

suppose in your date example that you wanted to make a calendar for all your arrangements the coming year. Let's say you have 200 arrangements already. You're not going to make 200 individual variables, each with different names. Instead, you would allocate room for one big variable containing 200 arrangements, and then simply save the address of this allocation.
In that example it is both clear why allocating memory is important (we are basically just storing information, doing stuff to it, and storing it again. notice how many times "storing" comes up in that explanation), and knowing where we put it.

I know the above explanation is not perfect, but if you start making programs you should soon notice that you care quite a lot about these things.

miturian
Light Poster
38 posts since Apr 2010
Reputation Points: 10
Solved Threads: 1
 

Miturian, Im starting to see how that would be more effective and less time consuming. If possible could you revise my date file with an example of your own allocating the space for 200 vars. Im hoping I could use it as a study guide.

Fbody im viewing the link you pointed out but it has terms that's unknown to me at this stage in my c++ journey so I just end up deciphering the code that looks familiar not really getting a clear understanding but thx anyway.

pharoah85
Newbie Poster
11 posts since Oct 2010
Reputation Points: 10
Solved Threads: 0
 

>>im viewing the link you pointed out but it has terms that's unknown to me at this stage in my c++ journey
They're the same terms you were trying to use in your OP.

Try this:
Start with this function tutorial, then read the next 5 or 6 pages.

Fbody
Posting Maven
2,930 posts since Oct 2009
Reputation Points: 833
Solved Threads: 393
 

Fbody Ive finished decipher the code from the first link youve referenced. Correct me if im incorrect but it seem to me that its more clean and precise to use pointers allowing functions to use the objects desired without adding size to the code vs making a copy of the object (which can get pretty big) every time i want to be able to use it in my code. Is that the significance of pointers??

pharoah85
Newbie Poster
11 posts since Oct 2010
Reputation Points: 10
Solved Threads: 0
 

That is one significant use of pointers. Yes. If you have the option, it is easier to do it via references. They're not as powerful, or agile, but their syntax is simpler.

There are other uses as well. Such as dynamic memory. Did you read that page in the tutorial I linked you?

Fbody
Posting Maven
2,930 posts since Oct 2009
Reputation Points: 833
Solved Threads: 393
 

YES!!Its is way more comprehensible and has code to try out to give more meaning to the topic being discussed. It makes mention of hexadecimal notation, is that something I needed to learn to be fully versed in c++. If so could you point out a link for that?

pharoah85
Newbie Poster
11 posts since Oct 2010
Reputation Points: 10
Solved Threads: 0
 

Hexadecimal (base-16) notation is actually pretty simple to understand. The representations of the numbers just take some getting used to (like anything else). It just uses 0-9 and a-f (representing 10-15) instead of simply just 0-9 (decimal).

For example:
How do you represent these numbers:

1. Sixteen:
   decimal (<strong>base 10</strong>):     16
   hexadecimal (<strong>base 16</strong>): 0x10

2. Two-Hundred Fifty-Five:
   decimal (<strong>base 10</strong>):     255
   hexadecimal (<strong>base 16</strong>): 0xFF
Fbody
Posting Maven
2,930 posts since Oct 2009
Reputation Points: 833
Solved Threads: 393
 

Back to deciphering again...

ex 1. written out in base 16: 0x10 0=number 1, 1= number 2,... F=number 15 correct?

so does ex 2: 0xFF == (0x(15,15)|| 0x(15));

pharoah85
Newbie Poster
11 posts since Oct 2010
Reputation Points: 10
Solved Threads: 0
 

You seem to understand the digits, now you need to figure out the position values.

In decimal notation, 0xFF means [TEX]( (15*16^1) + (15*16^0) )[/TEX] == (240 + 15) == 255

Fbody
Posting Maven
2,930 posts since Oct 2009
Reputation Points: 833
Solved Threads: 393
 

Does 3xBBB = (11*16^4) + (11*16^0) + (11*16^0)?
Also how would (14*16^5) + (14*16^3) be written out?
Like this: 974848?

pharoah85
Newbie Poster
11 posts since Oct 2010
Reputation Points: 10
Solved Threads: 0
 

ok I understand that but how do i convert decimal to hexadecimal notation?
ie 974848
9x10^5,7x10^4,etc; //decimal
??????//hexa

pharoah85
Newbie Poster
11 posts since Oct 2010
Reputation Points: 10
Solved Threads: 0
 

ee000

pharoah85
Newbie Poster
11 posts since Oct 2010
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: