• 0

[C++] If You Dont Understand Pointers


Question

If you don't understand pointers then compile this and see what it does. If you didn't have a pointer, every guess the random number would change making it harder to get it right. I made this thread because my friend didn't know what the purpose of pointers was and I thought it was a good idea to share with everyone.

#include <stdlib.h>
#include <iostream.h>

int main()
{
 ? ? short guess;
 ? ? short number = rand()%8; ?/* Creates a random # 1-8 */
 ? ? short* pNumber = &number; ? ?/* Creates the Pointer */
 ? ? do
 ? ? {
 ? ? ? ? ?cout << "Guess a # 1 - 8: ";
 ? ? ? ? ?cin >> guess;

 ? ? ? ? ?if(guess == *pNumber) ? /* If the guess is the first random # generated in variable number */
 ? ? ? ? ?{
 ? ? ? ? ? ? ? cout << "\n\nCorrect!\n";
 ? ? ? ? ? ? ? return 0;
 ? ? ? ? ?}
 ? ? }
 ? ? while(guess != *pNumber);
}

Link to comment
Share on other sites

Recommended Posts

  • 0
lol, im flying through the C# books im reading, but I dunno if you guys have a strong C++ foundation.

Yes, well do you have a part time job and attend summer classes too? I wouldn't say I have a "strong" c++ background, but I know the language and a lot of the concepts. Right now, I know C#, I'm just learning new concepts like OOP.

Link to comment
Share on other sites

  • 0
thats what i figured

why even bother with pointers when that does the exact same thing, 2 less linse of code

c++ is for idiots who think theyre going to get somewhere programmnig, but are really just nerds with no life

if youre going to do c++, youre going to be wokring in a big software company. making programs by yourself for yourself is just a waste of time with c++.

You sir are an idiot......

C++ isn't harder then C# if you know how to do it. Plus there are tons of things that you can do with C++ much easier then with any .NET language.

Link to comment
Share on other sites

  • 0
C++ isn't harder then C# if you know how to do it. Plus there are tons of things that you can do with C++ much easier then with any .NET language.

Like? :o

I'm not saying there aren't, I'd just like to see what you think is "easier"...

Link to comment
Share on other sites

  • 0
Yes, well do you have a part time job and attend summer classes too? I wouldn't say I have a "strong" c++ background, but I know the language and a lot of the concepts. Right now, I know C#, I'm just learning new concepts like OOP.

ahh, me being unemployed and working Saturdays only, isn't a fair comparison then i guess, lol.

C#: A Programmer's Introduction seems to be a good book for going from C++ to C#. After that, I wasted my money on "C# and the .NET Platform" which Amazon/ComputerBooks01 say is the best C# book available, lol. After C#, i plan on playing around with Access 2003 VBA and XML Web Services... "and now you know, the rest of the story......" ( i was bored so i decided to type, even though u don't care, lol)

@Schmoovey/gameguy:

Writing C++ console from scratch is way easier/quicker than writing the same in C#.

Link to comment
Share on other sites

  • 0
You sir are an idiot......

C++ isn't harder then C# if you know how to do it. Plus there are tons of things that you can do with C++ much easier then with any .NET language.

youre kidding right?

of course you are!

good one!

Link to comment
Share on other sites

  • 0
thats what i figured

why even bother with pointers when that does the exact same thing, 2 less linse of code

c++ is for idiots who think theyre going to get somewhere programmnig, but are really just nerds with no life

if youre going to do c++, youre going to be wokring in a big software company. making programs by yourself for yourself is just a waste of time with c++.

Yeah, learning is overrated. Just go with what's easiest. :rolleyes:

Stop being a troll.

Link to comment
Share on other sites

  • 0

It's interesting how a thread about pointers turned into one about language wars... :rolleyes:

Anyway, just use whichever you feel most comfortable with; nobody is forcing you to use anything.

Pointers have their uses, though as applications grow larger and more complicated, it helps to think in more abstract terms instead of worrying about things like pointers, off-by-one errors, and the like which are common in C/C++.

Just to be on topic, in my opinion, this site explains pointers in a clear and easily understandable manner:

http://cplusplus.com/doc/tutorial/tut3-3.html

bwx

Link to comment
Share on other sites

  • 0
c++ is for idiots who think theyre going to get somewhere programmnig, but are really just nerds with no life

if youre going to do c++, youre going to be wokring in a big software company.  making programs by yourself for yourself is just a waste of time with c++.

everything you have said above is incorrect. it might be in your best interests to have a think about what you're saying.

Edited by Target Audience
Link to comment
Share on other sites

  • 0
Like? :o

I'm not saying there aren't, I'd just like to see what you think is "easier"...

The .NET platform is great, it offers the developer a good set of tools. Though I've written a tweaker for the Radeon boards in the past which included overclocking. Creating and interacting with the code that does the overclocking is a lot easier (still hard) to do in C++ then in C# where you have to pull a lot of trick to be able to do it in the first place.

Anyways, my comment was more aimed at that fruitcake that claimed that people using C++ are nerds without a life. Making your own programs in C++ is not a waste of time if you know the language. You can develop anything just as fast in C++ as in C# with .NET, you just need to know what you are doing..... but that holds for C# too.

Link to comment
Share on other sites

  • 0

True, if you're working very close to the hardware, C/C++ is best. But .NET is meant to remove that layer so you don't need to worry about it. Drivers still need to be written in C (or maybe C++, I can't remember) for all versions of Windows. I think even longhorn will require drivers written in C/C++, despite it being the primary OS for .NET...

Anyways, my comment was more aimed at that fruitcake that claimed that people using C++ are nerds without a life.

Yeah, it was kind of unnecessary... :ermm:

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.