argh,i still couldnt understand some of it..do u have any idea where i could find more? bcause i already googled, and lots of them not for newcomer like me.
I think the understanding is that you want to know how to declare a variable of a certain type (such as integer, etc).
The responses are basically that declaring variables is the most fundamental aspect of computer programming,
and in virtually any given piece of C++ code you can find on the 'net, you will see examples of variable declarations.
Just look at any post here that has code in it if the tutorials are too advanced (though it does not get any simpler than the "Declaration of variables" section in http://www.cplusplus.com/doc/tutorial/variables/ ).
you can also declare variable of the same type in one line: type variable1, variable2, variable3; // ... or type variable1=value, variable2=value; // ...
here is an example of many types of variable declarations
the same as any other... the double/float type is just used to store a number that has a decimal value.
1 2 3
double d1; // makes a double variable with no value
double d2 = 1.5; // makes a double variable with the value 1.5
double d3 = 2; // makes a double variable with the value 2
Always remember to assign a value to the variable before you use it. For an example of why, try the following code:
char charArray[80];
for (int i = 0; i < 80; ++i)
std::cout << charArray[i];
You should see a bunch of characters. Maybe even different ones everytime you run the code.
As good practice, assign 0 to numerical types such as ints and floats, '\0' to chars, and "\0" to strings, e.g.
int myInt = 0;
char myChar = '\0';
std::string myStr = "\0";
i havent start compiling any programs yet,im a newcomer to c++
Make sure you have a balance of "book" work and practical work. By that I mean don't just read information/tutorials, actually give them ago and create things using given ideas and some of your own.
chrisname : "\0" is a waste of space since "" //empty string is a null-terminated 0 lenght string (e.g: an 1 lenght array consiting a 0), while "\0" is a 2 lenght array consisting two 0s.
To have embedded null characters in the string you need to specify the length of the string (which does not include the terminating null): std::string s( "\0", 1 );
Well... That's true, but it doesn't make much of a difference, for the most part. All instances of "\0" probably point to the same string, so the binary is only one char longer. std::string::string(const char *) will only read until the first zero, so it'll just create a zero length string. These are almost equivalent:
std::string s;
std::string s="";
The latter may run a few more instructions, since it needs to check the size of the C string.
helios : Other than the 1 byte memory overhead that "" has, in my eye it's much more readable than "\0", because "" is actually empty, but in "\0" there is one extra character which makes it look like it's not empty.
Anyway I've never seen "\0" before, that's why my eye caught up on this :)