+ 3
c++ beginner question
what is int do? for example int main() please explain simply so I can understand it tho xD
4 Answers
+ 8
int is a datatype for storing numbers.
Pretty good explaination here
https://www.tutorialspoint.com/cplusplus/cpp_data_types.htm
+ 2
thanks again
+ 2
There are a couple ways the 'int' keyword is used.
First in the declaration of integer variables within a function ( int ii = 0; ) That you use for some purpose in that function.
Second as the return value of a function ( int myFunc() {} ) This announces what too expect back when you call a function ( an integer, so capture it in an int!)
Third as a parameter to a function ( void myFunc2(int given) {} ) This case is very similar to the first, except that the value of the variable is set by whoever calls the function, so you sometimes have to do some checking to make sure it is a reasonable value.
I may well be forgetting something, so don't take this as definitive
0
Given ur snippet:
int main()
Int, in this case, refers to the return value (of type integer) of the 'main' function. By default C++ returns a '0' if everything runs smoothly. It will return a nonzero integer value if there is a bug/error.