Topic Index
Learning C/C++ code

Username:Password:
Log In
Copy Clerk
Posts: 78
Joined: 1 Sep 2008

I'm 16 and broke but I want to learn how to code in C/C++ does anyone know any websites that might help me with this.
I currently use Dev-C++ as my compiler. I know some basics but i cant find any in-depth information on it. I dont have alot of experiance but i know how to make a "hello World"
and a countdown.

Gone Gonzo
Posts: 1180
Joined: 1 Jul 2009

Ive got a similar problem. I want to learn to code but cant find any trustworthy sites to teach me. They are all "Click here to download." And before i do i check the rest of the site, and its got porn advertisements out the yin yang.

Press Junketeer
Posts: 444
Joined: 20 May 2008

There are alot of books out there on C++ Those are probably your best bet. Your central library
should have a HUGE arrangement of books and even CD's related to C. I don't have this problem mainly because my father is a Computer Programmer/Electrical Engineer and has literally a personal library of books. But aside from programs deep knowledge comes from those 1400 page texts. Amazon is actually a cheap place to get em if you want to own the book.

Infamous Scribbler
Posts: 617
Joined: 22 Oct 2008

Just search around the internet there a lot of good resources out there to get you started. A guy I work with has been programming since he was 8 so just start playing around with it, the best way to learn it is by messing up.

Infamous Scribbler
Posts: 566
Joined: 6 Mar 2009

http://www.gamedev.net/reference/list.asp?categoryid=20#214

Gavedev.net isn't really about teaching the basics of programming but there are some useful resources on that page. The book link right at the bottom of the page sounds promising. I've been learning how to program through a course so I haven't had to look into online information as much.

I haven't used the Dev-C++ compiler before and generally speaking tutorials for C++ will assume that you are using Visual Studio 2008. Any particular reason you are using Dev-C++?

Copy Clerk
Posts: 78
Joined: 1 Sep 2008

ive tried visual studios and it frustrated me a bit so i tried other compilers and dev has worked the best for me

Ushario:
http://www.gamedev.net/reference/list.asp?categoryid=20#214

Gavedev.net isn't really about teaching the basics of programming but there are some useful resources on that page. The book link right at the bottom of the page sounds promising. I've been learning how to program through a course so I haven't had to look into online information as much.

I haven't used the Dev-C++ compiler before and generally speaking tutorials for C++ will assume that you are using Visual Studio 2008. Any particular reason you are using Dev-C++?

ive tried visual studios and it frustrated me a bit so i tried other compilers and dev has worked the best for me. also thanks for the website.

Beat Writer
Posts: 137
Joined: 29 Apr 2009

halflobster:
I'm 16 and broke but I want to learn how to code in C/C++ does anyone know any websites that might help me with this.
I currently use Dev-C++ as my compiler. I know some basics but i cant find any in-depth information on it.

http://www.learncpp.com/

A brief perusal of this site, and it seems legit, and relatively in-depth. Hell, I might use it to reacquaint myself with the language. How much programming experience do you have?

Google is your friend, by the way. This was literally the first hit searching "learn c++"

Paperboy
Posts: 31
Joined: 25 Jun 2009

halflobster:
I'm 16 and broke but I want to learn how to code in C/C++ does anyone know any websites that might help me with this.
I currently use Dev-C++ as my compiler. I know some basics but i cant find any in-depth information on it.

Are you learning from scratch or do you have some programming background? If you've got no programming background then I'd suggest you start out with something easier, like Pascal, Delphi, C# or Java. But first learn the basics of imperative languages before moving on to the object oriented languages (C#, Java, C++, Smalltalk et al).

C is not typesafe and it does little to no checks on pointer boundaries, meaning you can write to your stack and heap space willy nilly. C++ is a bit better but you need to follow the rules, a lot of its unwritten and at times they are confusing unless you understand how the compiler works and how its memory model works.

Bjarne Stroustrup, creator of C++ said this:
"C makes it easy to shoot yourself in the foot. C++ makes it harder, but when you do, it blows away your whole leg."

That is exactly it, C is so powerful because it doesn't ask any questions and doesn't hold your hand. You ask "I want to shoot off my bigtoe." It will answer, "Sure, no problem".

I've been writing C++ for 10 years or so and it still manages to spring a surprise on me every now and again. If you've got some programming background and you're just interested in asking a few question regarding C++ then the C++ FAQ Lite is a pretty good site. If you're looking for a book for C++ beginners then I can share with you some of the books I have in electronic format, just PM me with an email address.

I can't end a discussion on C++ without mentioning Scott Meyer's books: "Effective C++", "More Effective C++" and "Effective STL"; anyone who thinks they know a bit about C++ should read those books, they are very useful resources and provide excellent C++ tips and tricks.

Anonymous Source
Posts: 7
Joined: 23 Mar 2009

I taught myself C++ using Learn C++ in 21 days by Jesse Liberty

Muckraker
Posts: 291
Joined: 19 Apr 2009

Bloodshed C++ use a visual compiler...im sure theres plenty out there.

and C++ in 21 days is a good reference

Muckraker
Posts: 348
Joined: 26 May 2008

Here's some reference for syntax and stuff like that for while loops, arrays, etc.
http://www4.ncsu.edu/~awwatkin/OTHER/C++.html

Gone Gonzo
Posts: 3816
Joined: 6 Feb 2008

I've been learning from C++: A Beginner's Guide by Herbert Schildt. It seems fairly decent so far, and if you can't afford to buy it, could you not order it (or any other books) in at your local library?

BANNED
Posts: 2473
Joined: 26 Apr 2009

If (you don't know C# || C++ code)
{
Always ask the internet for help;
Buy Learning for C# for Student; // C# is very similiar to C++
Give Up;

}

User was banned for: Poll: The Internet Ruined Gaming!!!. (Permanent)
Gone Gonzo
Posts: 1388
Joined: 17 May 2008

Visual C++ for Dummies ---- Start with this one

Don't hesitate to use the web to find out more, there are a lot of resources that I have used in the past.

May I suggest learning about C first instead of C++ ...

1. Learn about the variables
2. Conditional Statement
3. Iteration (looping: while / Repeat {} Until () / etc ... )
4. The infamous '*' and Addressing
5. Using Classes and structured programming

Then go to C++, learn about using classes, functions, overloading functions etc ... etc ...

Then, when you are confident enough ...

Get the C++ Bible ... that one is a BEAST of a book to read through ...

Also, consider C# after you mastered the basics, it's the future of programming or so I have been told.

BANNED
Posts: 2473
Joined: 26 Apr 2009

cainx10a:
Visual C++ for Dummies ---- Start with this one

Don't hesitate to use the web to find out more, there are a lot of resources that I have used in the past.

May I suggest learning about C first instead of C++ ...

1. Learn about the variables
2. Conditional Statement
3. Iteration (looping: while / Repeat {} Until () / etc ... )
4. The infamous '*' and Addressing
5. Using Classes and structured programming

Then go to C++, learn about using classes, functions, overloading functions etc ... etc ...

Then, when you are confident enough ...

Get the C++ Bible ... that one is a BEAST of a book to read through ...

Also, consider C# after you mastered the basics, it's the future of programming or so I have been told.

C# is the next step after C++, but it's not as fast as C++.

EDIT: From what I've heard it eventually will be, but as of now it's not. XNA uses C#.

User was banned for: Poll: The Internet Ruined Gaming!!!. (Permanent)
Paperboy
Posts: 40
Joined: 15 Mar 2009

I still see the words "syntax error" in my nightmares...a very unhappy two months...

Paperboy
Posts: 22
Joined: 4 Nov 2007

I'm 16 and broke but I want to learn how to code in C/C++ does anyone know any websites that might help me with this.
I currently use Dev-C++ as my compiler. I know some basics but i cant find any in-depth information on it. I dont have alot of experiance but i know how to make a "hello World"
and a countdown.

1. Get Visual Studio Express, it's free, has tons of useful features and you'll have to get used to similar types of IDEs eventually if you ever go into it professionally. It's normally the standard compiler for most uses, any decent C/C++ programmer should be familiar with it.

2. Start with just plan vanilla C and move to C++ after you're done with that. For sources, I'd recommend "C Programming - A modern Approach, K.N.King", "C++ Primer Plus, Stephen Prata" and once you're comfortable with the language "Effective C++, Scott Meyers". Take it one step at a time, make sure you understand all the fundamental concepts and tools (conditionals, iteration, pointers, classes, memory allocation, the standard library) before moving into more complex stuff.

3. Forget about "easier languages". I'd recommend going with C then C++ instead of whatever else (C#, Java, etc). You can pickup those in a weekend once you properly understand C++ - it's better to struggle with the low level details now, while you're still learning, than not learning it at all and later on having to correct a swath of misconceptions and bad programming practices/habits you may have built up because all the little details were taken care of for you behind the scenes.

Once you understand what's actually going on at the low level in your code, then you can move on to using code that makes it easier for you (i.e. write your own list once before you start using the STL one). Otherwise down the road, you'll start getting seemingly weird problems which arise from the compiler or the language guessing you mean one thing when you actually mean another and you won't understand why it's happening (i.e. like when C# uses references and when it doesn't, for example).

4. As far as internet references, most of the time you'll be ok with http://www.cplusplus.com/ , http://www.parashift.com/c++-faq-lite/index.html and http://www.msdn.com/. Those failing, there's always forums you can ask around at - if the documentation isn't enough help (and the documentation should always be the first place you go to when in doubt), going straight to people is your next best bet. If it's a more complicated question that isn't necessarily covered by your average books or sites, you can always ask at http://stackoverflow.com/.

Muckraker
Posts: 310
Joined: 4 Jul 2009

the_abhorsen:
I still see the words "syntax error" in my nightmares...a very unhappy two months...

Heh. I'm doing code in visual basic as part of a college/sixth-form course, all I can say is "type mismatch" D:

Gone Gonzo
Posts: 2464
Joined: 4 Jun 2009

A Pious Cultist:

the_abhorsen:
I still see the words "syntax error" in my nightmares...a very unhappy two months...

Heh. I'm doing code in visual basic as part of a college/sixth-form course, all I can say is "type mismatch" D:

I did a college course and learnt visual basic after teaching myself C++ for awhile. Hate Visual Basic, but it is alot simpler and to get basic windows apps going for your "hello world" ect, jazz.

Im happy I learnt C++ before I learnt Visual Basic.

OP: I bought aload of books instead as I didn't feel internet tutorials were as easy to learn the very basics with. Taught myself how to use Flash and use Actionscript from the internet though, (after learning C++ from a book first)

Press Junketeer
Posts: 375
Joined: 23 Jul 2008

Would Visual Basic be a good starter language? I saw it was advised to at least know some language before attempting C/C++.

Gone Gonzo
Posts: 1201
Joined: 23 Oct 2008

cainx10a:
Also, consider C# after you mastered the basics, it's the future of programming or so I have been told.

Needs more functional languages IMO. Haskell 4 lyfe.

Reep:
Would Visual Basic be a good starter language? I saw it was advised to at least know some language before attempting C/C++.

VB isn't bad as a learning language, but actually coding in it is a nightmare. There's a lot of extra bullshit that VB requires that gets old, and there's some functionality it's missing that also gets annoying pretty quick.

I learned on Java, which is nice and user friendly and relatively easy to get into, and there's no way to have pointer errors or mallocs go bad.

@OP, there's one very important thing you should know before you do any work with C:

Have something easily repairable on hand. Seg faults are the fucking devil and I guarantee you will want to smash something due to one (or more) at some point.

Other than that, what Kaelan said. Learning the basics now will definitely help in the long run, take it from someone who's been through that. It will frustrate you to all hell and back now, but it will make things much, much easier down the line.

Gone Gonzo
Posts: 1201
Joined: 23 Oct 2008

the_abhorsen:
I still see the words "syntax error" in my nightmares...a very unhappy two months...

Syntax errors at least tell you where the error is.

It's a lot more fun trying to figure out precisely where in 1500 lines of code, that someone else wrote, it goes FUBAR.

Infamous Scribbler
Posts: 566
Joined: 6 Mar 2009

Oolinthu:
*snip*

Thanks for linking that site Oolinthu, I decided to give it a look over and it took me less than a minute to learn something new. From my brief look so far I would recommend it.

Who knew I'd been using an incorrect form of hungarian notation!

I started with C++ and while it has been a real trial at times I'd like to think it has paid off.

Gone Gonzo
Posts: 1131
Joined: 3 Dec 2008

Cixelsid:

halflobster:
I'm 16 and broke but I want to learn how to code in C/C++ does anyone know any websites that might help me with this.
I currently use Dev-C++ as my compiler. I know some basics but i cant find any in-depth information on it.

Are you learning from scratch or do you have some programming background? If you've got no programming background then I'd suggest you start out with something easier, like Pascal, Delphi, C# or Java. But first learn the basics of imperative languages before moving on to the object oriented languages (C#, Java, C++, Smalltalk et al).

If you want to learn a purely imperative language, then I'd say C is the one, since very few other such languages are in use today. I don't think you need to start with C - it's hard to get something useful done with it at first as it involves so much manual labor - but if you are motivated it's a good first language and you really learn from the ground up.

IMO, Python is a fine choice for first language - simple language, simple syntax, lets you learn what programming is about without worrying about details like memory management, and lets you easily make stuff useful in the real world which is motivating.

C is not typesafe and it does little to no checks on pointer boundaries, meaning you can write to your stack and heap space willy nilly. C++ is a bit better but you need to follow the rules, a lot of its unwritten and at times they are confusing unless you understand how the compiler works and how its memory model works.

Bjarne Stroustrup, creator of C++ said this:
"C makes it easy to shoot yourself in the foot. C++ makes it harder, but when you do, it blows away your whole leg."

That is exactly it, C is so powerful because it doesn't ask any questions and doesn't hold your hand. You ask "I want to shoot off my bigtoe." It will answer, "Sure, no problem".

I've been writing C++ for 10 years or so and it still manages to spring a surprise on me every now and again.

Ergo: with C, you might blow your toe off many times before learning not to do it. With C++, you never stop blowing your leg off.

I can't end a discussion on C++ without mentioning Scott Meyer's books: "Effective C++", "More Effective C++" and "Effective STL"; anyone who thinks they know a bit about C++ should read those books, they are very useful resources and provide excellent C++ tips and tricks.

I have read the first two, and they are a very good exposition of why anyone who doesn't specifically need C++ should stay the hell away from it. Especially as first language.

Gone Gonzo
Posts: 1131
Joined: 3 Dec 2008

Also, when it comes to learning an entire programming language, there is no way you are so broke you can't afford one book. (Or so lazy you can't pick it up from the library.) If you decide C is what you'll learn, then get a C book. As far as I know, there is no website on C that equals a good book. Learning a language is not a matter of knowing a few nifty tricks.

"Programming in C, 3rd edition" by Kochan is a sure bet. It's one of the few C books updated to the latest C99 standard, and wordy enough for a new programmer.

"C Programming Language, 2nd edition" by Kernighan and Ritchie, the original designers of the language, is good but too terse considering that you are new to programming and going to be learning alone.

Press Junketeer
Posts: 378
Joined: 18 Apr 2008

accelerated c++ is a good book but it expects you to have already have experience in programming in general, it teaches you c++ not c with some other stuff

Gone Gonzo
Posts: 3364
Joined: 23 Oct 2007

cainx10a:
Also, consider C# after you mastered the basics, it's the future of programming or so I have been told.

I wouldn't go anywhere near C#; it's too proprietary for my liking, even with the whole ISO standardisation. C is going to continue to be important; it's standardised, it can be compiled with the professional-standard GCC compilers, it's quick and it's still at the root of a lot of operating systems.

I'd predict that FORTRAN has a longer potential life-span than C#, because really, Real Programmers Don't Use PASCAL. FORTRAN might be just about the most difficult programming language that's still useful, but for what it's used for, it's quicker than anything short of assembly language.

Paperboy
Posts: 35
Joined: 29 Jan 2009

Don't use Dev C++, pretty much any professional developer will advise you to use Visual C++.
http://www.microsoft.com/express/

If you really don't want to use it, then the best alternative would be Code::Blocks.
http://www.codeblocks.org/

Gone Gonzo
Posts: 3580
Joined: 8 Feb 2009

I have a book on it. Forgot where I put it. I don't know. You should get books on it and while your not reading the books, read stuff on the interwebs about it. If the interwebs =/= the book, chances are the website is a lie.

Gone Gonzo
Posts: 1131
Joined: 3 Dec 2008

Kakkoii:
Don't use Dev C++, pretty much any professional developer will advise you to use Visual C++.
http://www.microsoft.com/express/

If you really don't want to use it, then the best alternative would be Code::Blocks.
http://www.codeblocks.org/

Why would you recommend someone new to programming use an IDE at all?

Paperboy
Posts: 31
Joined: 25 Jun 2009

Kaelan:

3. Forget about "easier languages". I'd recommend going with C then C++ instead of whatever else (C#, Java, etc). You can pickup those in a weekend once you properly understand C++ - it's better to struggle with the low level details now, while you're still learning, than not learning it at all and later on having to correct a swath of misconceptions and bad programming practices/habits you may have built up because all the little details were taken care of for you behind the scenes.

Kaelan, I understand your reasoning and to some extent I agree with you. A lot of lazy programmers should learn a bit of C++ in order for them to be conservative with their memory management. A language with a garbage collector is a luxury that breeds inefficient code. That is, until you understand how the garbage collector works and you start specifically coding so that it can function correctly.

But I don't think a person who's never coded in his life should just jump into C/C++, and I don't believe any person can say they "understand C++" until they've been coding it for a few years. I've met a lot of junior programmers who say they "understand C++" and then when I ask them to write an overloaded assignment operator for a specific class they never get it right. Hell, even the experts have a hard time agreeing, e.g. Anatomy of the Assignment Operator and it's revised companion Assignment Operator Revisited.

This is basic principles, if you don't analyze your class from every angle or you update it and forget to update the copy constructor and/or assignment operator: BAM! memory leak.

I've glowcoded apps that have been running for years at military installations written by "C++ Experts" and found horrendously written code, memory leaks, and mem access violations/seg faults.

It's for that reason that I see more and more companies turning to languages that hold the programmer's hand. Even myself, I put my juniors on UI code in C# or Java before I let them loose on the algorithms in C++, if they fuck up in Java, at least they get a nice exception stack trace and it doesn't pull the whole system down. If you don't know a bit of assembly and you don't know how to traverse memory addresses to find out what your pointers really are referencing, I'm not letting you near a C++ debugger.

Starting with easier languages allows a person to feel what its like to create something and see it work. Starting out with C++ can be very disheartening and confusing unless you have someone around to tell why your code isn't working. This is a classic example:

char* getString()
{
char szStr[5];
szStr[0]='t'; szStr[1]='e'; szStr[2]='s'; szStr[3]='t'; szStr[4]='/0';

return szStr;
}

I've seen this many times in various forms, some compilers will warn you that you are passing an address to a temporary variable - a lot of them don't.

The problem with code like that above is that the access violation (or segmentation fault if you use gcc) almost never ever occurs where you expect it would or indeed even at the same place if you run the program a few times. It's the kind of problem that a beginner programmer would be stuck with for hours or days, and a lot of times they'll just give up.

In my opinion, step number one is to get the syntax down, Java and C# share almost the same syntax as C++ and that in my mind is a good starting point. If you're still getting syntax errors after your second compile you should slap yourself, write your syntax right the first time.

Then focus on OOP principles, once you understand classes and instances of classes you can focus on your memory model, how your compiler assigns space for arrays and objects. This you can't do without a basic understanding of Number Theory, you need to know how to convert between numbers of different bases, and what that means at an electronic level.

Move on to C pointers and then C++ references, you can't understand C++ references if you don't grasp pointers. Once you understand why the following is evil:

char* pchr = 0;
char& rchr = *pchr;

you can start focusing on all the other good stuff; headers and prototyping, macros, structs and C++ classes, member overloading and shadowing, templates, function pointers (I wish other languages had this) and much much more!

Finally, buy and read books on the subject, there's a lot of material available, written by much smarter people than yourself, C++ is not something you do over the weekend (like Visual Basic), it requires effort, patience and understanding. Understanding only comes when you acquire the knowledge from people who have already gone through the process.

Really, it takes years to wrestle C++ to the ground and make it your bitch, most of the time it'll ride you like a disease riddled dollar-per-hour whore and leave you feeling sick, vulnerable and guilty that you paid for the experience...

...and wanting for more, because C++ is power, it lets you do what you want and you get a real sense of accomplishment when you get it to do what you want it to.

EDIT: That last bit there wasn't directed at Kaelan, it was directed at all beginner programmers in general.

Paperboy
Posts: 22
Joined: 4 Nov 2007

Well yes, of course it does take quite a while to understand every last bit of the language thoroughly. But that's why you start with C, which is far easier to grasp. The point isn't really to become a complete C++ guru, but to understand what's going on behind the scenes when you program things.

After shooting yourself in the foot enough times, you start first learning *that* you are in fact shooting yourself in the foot when you do certain things (which, as trivial as it sounds, is actually not always easy to tell, especially with languages that "take care of the hard stuff for you"). Then you learn *why* that was indeed shooting yourself in the foot. And then you start understanding what's actually going on and learn to not do it anymore. And so on and so forth.

If you did something like that in a language that quietly "fixed" it for you...well, you're definitely going to be in trouble down the line, because at one point or another it's not going to do what you were actually trying to make it do - and chances are you'll have absolutely no idea why. And at that point it's much harder to correct fundamental mistakes made or misconceptions held.

If you first learn how to handle memory by managing it yourself, it'll be that much easier for you when you go somewhere else (say, Java) and have to deal with garbage collector shenanigans. If you've always had it taken care of for you and down the line suddenly have to deal with a problem that requires knowledge of how the memory is being handled....weellll, then you're gonna have a lot of catching up to do before you actually "get it".

Would Visual Basic be a good starter language? I saw it was advised to at least know some language before attempting C/C++.

The only valid answer to that question is "it depends". What language(s) you should learn will depend on what you're going to program for. If you're going into something where performance is absolutely critical (like, say, programming games) then you're going to want something like C and C++, that gives you full control of what's going on (and the responsibility of keeping managing it all yourself). If you're more interested in web development, Java and Python are good starting points. C# is great for quickly prototyping ideas before writing a large detailed program in some other language, give how easy and quick it is to put something simple up and running. Etc,etc.

I still see the words "syntax error" in my nightmares...a very unhappy two months...

Syntax errors at least tell you where the error is.
It's a lot more fun trying to figure out precisely where in 1500 lines of code, that someone else wrote, it goes FUBAR.

const void &Enso = *static_cast<const void*>(0);

D:

 
Topic Index

Reply to Thread

You must be logged in to post.
Username:  
Password:  
  

Not registered? Sign up for a free account!

Forum Jump: