+ 3

c++ beginner question

what is int do? for example int main() please explain simply so I can understand it tho xD

10th May 2017, 12:54 AM
Kyroh
Kyroh - avatar
4 Respuestas
+ 8
int is a datatype for storing numbers. Pretty good explaination here https://www.tutorialspoint.com/cplusplus/cpp_data_types.htm
10th May 2017, 12:56 AM
jay
jay - avatar
+ 2
thanks again
10th May 2017, 12:56 AM
Kyroh
Kyroh - avatar
+ 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
10th May 2017, 4:12 AM
Jim
Jim - avatar
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.
10th May 2017, 6:05 AM
Dnny Frley
Dnny Frley - avatar