+ 17
What is difference between "int" we use before main and as an integer variable?
39 Answers
+ 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
+ 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.
+ 6
it is a global variable. you can use this declaration in whole program.
+ 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
+ 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
+ 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
+ 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.
+ 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
+ 2
int main() means you want your output only in integer ,
but in int variable you're declaring data type of that variable .
+ 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
+ 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.
+ 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..
+ 2
int before main represents that return type of main is int whereas integer variable holds integer
+ 2
int is a variable
but int main is a function that return a value
+ 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
+ 2
in main () integer is used to take a return value from a program
+ 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
+ 1
int x is a data type
int main () is a return type
+ 1
int main() means main function will return integer while int as variable define data type pf declared variable
+ 1
i can't understood arrays š