Talk:C++/Variables and User Input

Feel free to add anything that you'd like :) I'm definately not even close to an expert at C++, so if you see me hacking my way through something, please fix it and make it better! Thanks,

Giawa

int main
int main (int argc, char * const argv[])

None of this is explained. Is it needed? My code works fine without it. --12.150.181.20 17:43, 12 December 2007 (UTC)

int main (int argc, char * const argv[]) explained
Here's an explanation as to where argc and argv come from.

Back when computer programming was young, computers ran all programs in a terminal (similar to MS-DOS). Is MS-DOS you have the ability to append commands when executing a file. This was an easy way to provide input to the program. So, for example:

C:> myProgram.exe input.txt output.txt

That is me running myProgram.exe in terminal, with two other commands appended to the end. In this case I provided an input and an output for the program to work with. Programmers needed a way to access these extra commands that users appended to the program, so that is where argc and argv come from. The integer argc stores the number of commands that are appended, and the array of character pointers will point to the character arrays, which store the actual data (in this case one character array will store "input.txt" and the other will store "output.txt").

Some fussy compilers will require that argc and argv exist, but most will accept main as well.

(Giawa 10:58, 15 December 2007 (UTC))

int value
I have a question about the maximum value of an int. How can you calculate a number larger than 2147483647? In Lesson 6 for example you explain how to calculate factorials. 17! returns a negative value and 13! is already too high.

Tappie 20:33, 2 April 2008 (UTC)
 * If you are a french friendly reader I invite you to learn from the french version I maintain. That the teacher dont said is that numbers in computers are array of byte and bytes are array of bit witch can take "0" or "1" value. In conventional computers bytes are array of 8 bit (256 values from 0 to 255 then 2^8). Ints are array of 4 bytes so 32 bits then 2^32 values from 0 to 2^32-1 for unsigned and from -(2^32)/2-1 to +(2^32)/2 for signed.
 * unsigned or signed mode is choosed by programmer where computer only understand BITS. that's why you get negative numbers on 17! in fact you are in size overflow !

Compilers
At this point when you start introducing code hopefully people will want to code along with you and test out their own code. It might be a good idea to include some simple instructions on how to use a compiler (perhaps gcc) or maybe link to a page where this info can be found.