Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 A Start on C++ Some First Programs/Questions
Index -> Programming, C++ -> C++ Help
Goto page Previous  1, 2, 3, 4, 5
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
wtd




PostPosted: Sun Jul 10, 2005 10:21 pm   Post subject: (No subject)

[Gandalf] wrote:
Too bad, at least it's possible...

Also, while looking at the source code for one of my favourite games, I saw that it uses printf(); even though it's coded in C++. Some of the books I am learning from use it, and other C-like functions as well. I think they might be a part of the 'standardized' library too. Why?


Backwards compatibility.

Windows XP will let you run apps written for the 16-bit Windows API. That doesn't mean you should write them. Smile
Sponsor
Sponsor
Sponsor
sponsor
[Gandalf]




PostPosted: Tue Jul 19, 2005 2:12 pm   Post subject: (No subject)

What are pointers for? I was looking at the very basics of them, and I think I understand how they work, but why use them? When you are say, showing a variable, why not show the actual thing instead of the pointer?
wtd




PostPosted: Tue Jul 19, 2005 2:18 pm   Post subject: (No subject)

[Gandalf] wrote:
What are pointers for? I was looking at the very basics of them, and I think I understand how they work, but why use them?


A pointer is just a variable containing a number, which happens to be the location of some value in memory. This becomes incredibly valuable, primarily because your pointer can be null. It can refer to nothing.

A normal variable has to hold some kind of value. If you declare an integer, it has to hold a value. Even if that value is zero, it's still a value.

But a pointer that's zero, well that refers to nothing. Nad, zilch, squat. And, you can can determine if it is null or not at run-time.

[Gandalf] wrote:
When you are say, showing a variable, why not show the actual thing instead of the pointer?


Could you please post an exact example?
wtd




PostPosted: Tue Jul 19, 2005 4:30 pm   Post subject: (No subject)

wtd wrote:
[Gandalf] wrote:
What are pointers for? I was looking at the very basics of them, and I think I understand how they work, but why use them?


A pointer is just a variable containing a number, which happens to be the location of some value in memory. This becomes incredibly valuable, primarily because your pointer can be null. It can refer to nothing.


It should be noted that this use of pointers becomes unnecessary ina language with support for variant types.

code:
data Maybe a = Just a | Nothing

indexOfValueInList :: a => Int ->a -> [a] -> Maybe Int
indexOfValueInList _ _ [] = Nothing
indexOfValueInList n val (x:xs)
  | val == x = Just n
  | otherwise = indexOfValueInList (n + 1) val xs
Display posts from previous:   
   Index -> Programming, C++ -> C++ Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 5 of 5  [ 64 Posts ]
Goto page Previous  1, 2, 3, 4, 5
Jump to:   


Style:  
Search: