Talk:C++/Variables and User Input

Latest comment: 16 years ago by Tappie in topic int value

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

Notes

edit

Hello everyone, I am finally back. Lets get started right away on lesson number two! First off, some housekeeping business on my part.

- Firstly, I love coming back here and seeing all the changes. My first lesson has been developed and expanded so much, it is awesome to see the power of Wikiversity. Great feeling.

- Secondly, I see that there are some new articles up! Very cool stuff.

- Thirdly... I feel as though I should apologize. I wrote that last lesson very quickly and was hoping to keep writing the following night. University, alas, is an extremely time consuming affair, so this is one of those projects that is on the back-burner. I've also been trying to develope my own understanding of the language a bit more, as I definately was never taught how to do some things properly.

Note: For some reason, firefox is sometimes having a hard time seeing the underscore in my variable names... I'll go through and remove them when I have some time to eliminate confusion.

Anyways, enough of my ramblings.

int main()

edit

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)Reply

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

edit

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))Reply

int value

edit

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)Reply

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

edit

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.

Return to "C++/Variables and User Input" page.