+ 17

What is difference between "int" we use before main and as an integer variable?

15th Jun 2016, 12:57 PM
Nisarg Uchiha
Nisarg Uchiha - avatar
39 Respostas
+ 62
int main() means that the data type returned from the main FUNCTION is an integer. int x=10 means that the VARIABLE x is an integer
15th Jun 2016, 1:10 PM
Matteo Sambruna
Matteo Sambruna - avatar
+ 8
Some additional info: Operating systems expect programs to return some value on exit. It can be the result of your program or an error code (more common thing). That's why main function returns a value. It's the only function that is called from your OS.
5th Dec 2016, 9:45 PM
drunckoder
drunckoder - avatar
+ 6
it is a global variable. you can use this declaration in whole program.
14th Dec 2016, 2:19 PM
Nawaj Shareef
Nawaj Shareef - avatar
+ 5
int before main , which indicates that the function returns an integer value. (return 0; etc,) if operations without returning a value. Such functions are defined with the keyword void. ×××××××××××××××××××× int x=1; in above code int indicates the datatype of variable
14th Dec 2016, 4:22 PM
chetan mali
chetan mali - avatar
+ 5
int main() is the type of the main function which is returning integer value, however, only in main function return 0 means successful termination of your program, in other words it send back the result to compiler (which calls the function main itself) int name_of_var; means you are declaring the integer type variable which stores only 4 bytes of information (see the differences of data types) and then you can put a value to your variable through assignment method like (int x=3; puts 3 to memory cell of x, stores the data). Hence you must provide the appropriate data type of return of your functions, or show that is not return anything (void type). That's it
14th Dec 2016, 10:47 PM
Jasur-D
+ 3
Int before main() is used as a return type that means while compilation the compiler expects a integer value in return before the function is closed otherwise warning is given or in some compilers error is thrown whereas in case of variables int refers to their data types which shows that those variables are allowed to store only int values
14th Dec 2016, 6:36 PM
Arpit Luniya
Arpit Luniya - avatar
+ 2
the difference is declaration of function and variables, that is in the function, int main() int is return type of the main function and in the variable, int s=23, int is data type of variable s.
13th Dec 2016, 12:33 AM
Shubham Rana
Shubham Rana - avatar
+ 2
int before main works as a return data type but when it is used before a variable means the variable can hold only integer values
13th Dec 2016, 4:02 AM
Am@n
Am@n - avatar
+ 2
int main() means you want your output only in integer , but in int variable you're declaring data type of that variable .
13th Dec 2016, 1:53 PM
Dixem
Dixem - avatar
+ 2
int before main called global variable and can be used anywhere in hole program... but int in main can use for only main section in program
13th Dec 2016, 6:12 PM
Aadil Sayyed
Aadil Sayyed - avatar
+ 2
actually both int are same. int main () is a function and int x=110; kind of things are variables. if you have noticed, the last line of int main () is return 0;. This 0 is the integer is returned by the main () function. you can also use void main () too. but as voids don't return anything. you don't need to use return 0; like... #include <iostream> using namespace std; void main (){ cout <<"perfect"; } and... #include <iostream> using namespace std; int main (){ cout <<"perfect"; return 0; } will have same output.
14th Dec 2016, 11:27 AM
Spandan Mondal
Spandan Mondal - avatar
+ 2
int main()means fuction will return value processing those codes which will be executed..if you want something from function then you can use it... N if I write int a=10 then ....the value stored in a is evaluated 10 n has a data type of integer..it is a type of declaration...of variables that it gonna be hold which type of values..
14th Dec 2016, 2:04 PM
Karan Desai
+ 2
int before main represents that return type of main is int whereas integer variable holds integer
14th Dec 2016, 5:52 PM
Pulluri Arvind
Pulluri Arvind - avatar
+ 2
int is a variable but int main is a function that return a value
14th Dec 2016, 6:03 PM
Siphesihle
Siphesihle - avatar
+ 2
Its clear mate! An int i.e declared before main is globel variable.. And this has the ability to be used anywhere in program. And normal int is may be a local variable
15th Dec 2016, 5:40 AM
Rahul Gupta
Rahul Gupta - avatar
+ 2
in main () integer is used to take a return value from a program
7th Jan 2017, 8:59 AM
Sandeep Sahu
Sandeep Sahu - avatar
+ 1
in some type of programs when there is nothing to cout we use a small instruction line " return 0" .as 0 is int value therefore we make out main program as int
15th Jun 2016, 1:19 PM
Syed Mohsin Matloob Bukhari
Syed Mohsin Matloob Bukhari - avatar
+ 1
int x is a data type int main () is a return type
15th Jun 2016, 1:29 PM
Sardor
Sardor - avatar
+ 1
int main() means main function will return integer while int as variable define data type pf declared variable
13th Dec 2016, 7:16 AM
ABHISHEK KUMAR JHA
ABHISHEK KUMAR JHA - avatar
+ 1
i can't understood arrays 😐
14th Dec 2016, 3:14 PM
Mamdouh AL FARRA
Mamdouh AL FARRA - avatar