+ 1

How do we get to know where to use void main and where to use int main

25th Mar 2020, 6:54 PM
Palakh Koyalkar
Palakh Koyalkar - avatar
2 Answers
+ 1
Int is return type of our output Suppose a function int func() { Int c = 10; return c; } Here we return some variable c that has integer datatype So we use int data type for our function But supposed function like this void func(){ cout << "Hello"; } Here we return nothing not use return keyword. So we used void here
25th Mar 2020, 7:55 PM
Saad Saleem
Saad Saleem - avatar
+ 14
Palakh Koyalkar We use int main(), when we are returning int data to main(). With int as return type we also write return 0; at the end of program to show that program executes successfully as main() returns value to OS. And use void main() , when main() is not returning any value (data) .
25th Mar 2020, 8:13 PM
Vinesh Wadhwani
Vinesh Wadhwani - avatar