hehe. It just does. Here's an alternative:by (no login)
C++ doesn't require you to tell it what data type you're printing. In my opinion, C++ looks better than C, and it is easier to program quickly in. Take a look at the two programs:
int a = 50; float b = 10.;
print( "%d%f\n", a, b );
int a = 50; float b = 10;
cout << a << b;
Both do the exact same thing. This part of C++ is easier to understand, but all the other parts of it are more complex than just C.
As for why it needs to know the %d, %f, etc. You send it a few bytes in memory, but it doesn't know what to do with it. You send it 00000000 00000000 00000000 00001010 for example. Is this a float or a long? You send it 11111111 00000000 for example. Is this a short or a string? When you send these things to the printf function, it doesn't get what type they are - it only gets their value.
C++ is slightly different. It has the cout object (forget this for now). It also has LOTS of functions - one for every possible datatype you could send to cout. It has a function for ints, floats, chars, etc. When you call a function in C++, it doesn't just look for the matching function name - C++ looks for the matching function name AND the matching parameters. You can have two functions in C++ with the same name but different parameters. For example:
void Function( int a );
void Function( float b );
That's valid. In C you can't do this.
Anyways... That's sorta how cout works. I know you asked about printf, but I don't know as much about that function. I do know that you have to tell it what kind of data it's receiving.
|Response Title||Author and Date|
|Right. That's why C++ is like "Super-C" (Nintendo pun intended).||rpgfan3233 on Mar 22|