I learnt C without realising it....how the?

Started by
24 comments, last by Will F 18 years, 8 months ago
Quote:Original post by theadamSGT
okay.


And what? Now you know...how are you gonna help?
Advertisement
just a chance that you might have been learning c++ because c++ can use printf too
if you want to learn c++ here it is http://www.gamedev.net/community/forums/topic.asp?topic_id=333728
Quote:Original post by theadamSGT
just a chance that you might have been learning c++ because c++ can use printf too
if you want to learn c++ here it is http://www.gamedev.net/community/forums/topic.asp?topic_id=333728


Cool...I'll try using it myself....(why do they always make you use cout<< in c++?)
i dont have to its just because thats what i learned
Quote:Original post by theadamSGT
i dont have to its just because thats what i learned


The world is full of some dumb, dumb people....
Quote:Original post by ReneGade RG dev
Quote:Original post by theadamSGT
just a chance that you might have been learning c++ because c++ can use printf too
if you want to learn c++ here it is http://www.gamedev.net/community/forums/topic.asp?topic_id=333728


Cool...I'll try using it myself....(why do they always make you use cout<< in c++?)


I'm a newb myself when it comes to C++ (and other programming languages) but my response is probably more useful than the previous too.

<< Is a operator, similar to +,-,/,*,^ etc. and both cout and "Hello World" are operands.

Since << looks to the right of it (this may seem vague but I think you've just got to accept this, it's how it's programmed), i.e.

cout << "Hello World"

<< looks to the right of itself and it applies what it finds ("Hello World") to the function cout. cout stands for console output.

Since I'm new and haven't really used it thoroughly I don't see why they don't just have a function like the one in C#: Console.Write("Hello World"); which is much neater. I assume it's for flexibility in terms of memory management.
If you're continuing with C++ you'll learn why cout is better than printf.

But for now just accept that the c++ stream-model is typesafe while the c stream-model isn't.


Quote:Original post by TomX
Since I'm new and haven't really used it thoroughly I don't see why they don't just have a function like the one in C#: Console.Write("Hello World"); which is much neater. I assume it's for flexibility in terms of memory management.

Nah, it's just those C++ers love to their operator overloadings <ducks>

In the end, the difference between:
a + b;

and:
a.add(b);

is just style.

shmoove

Quote: C does run faster than C++ due to it being at a slightly lower level, but this probably won't concern a beginner much.


C++ is not inherently slower that C.

Quote:Since I'm new and haven't really used it thoroughly I don't see why they don't just have a function like the one in C#: Console.Write("Hello World"); which is much neater. I assume it's for flexibility in terms of memory management.


It's nothing to do with memory management, as shmoove said the difference between the two is just style. Now consider this code:

cout.write("Hello world here's a number ").write(number).write(" here's a string  ").write(string);cout << "Hello world here's a number: " << number << " here's a string " << string;


Personally I far prefer the second option. Note that type-safe variable length argument lists are not available so using the same style as the .Net class library's Console.Write is not an option.
Quote:Original post by shmoove
In the end, the difference between:
a + b;

and:
a.add(b);

is just style.
a.add(b.add(c.sub(d.add(e.add(f)))));
I'd say there's more than style to it.

Quote:Original post by ukdeveloper
C does run faster than C++ due to it being at a slightly lower level, but this probably won't concern a beginner much.
False.

Quote:Original post by ReneGade RG dev
(why do they always make you use cout<< in c++?)
First off, "they" don't make you use anythng. Second, it's cout, not cout<<: cout is an object (it encapsulates a representation of the console output stream and inherits a set of generic stream properties), with operator << overloaded to serve as its insertion mechanism. The insertion operator is overloaded for all intrinsic and standard library types with meaningful textual representation (it doesn't make any sense to print a vector, but it makes sense to print the strings in the vector) and can be overloaded by the developer for user-defined types (you can create an insertion operator for your vector3d type and then be able to write cout << v3d;).

The insertion operator is typesafe, unlike "the incredible exploding printf" in C (pass data with the wrong format specifier and enjoy the possible fireworks), as well as marginally less vulnerable to buffer exploits. These are just a few of the advantages of cout over printf, but most of them won't become meaningful to you until you start to do more than just print text to the screen. Give it time and you'll come to see that it's a Good Thing™.

Happy hacking.

This topic is closed to new replies.

Advertisement