Search
 
SCRIPT & CODE EXAMPLE
 

CPP

What should main() return in C++?

The return value for main indicates how the program exited. Normal exit is 
represented by a 0 return value from main. Abnormal exit is signaled by a 
non-zero return, but there is no standard for how non-zero codes are 
interpreted. As noted by others, void main() is prohibited by the C++ 
standard and should not be used. The valid C++ main signatures are:

int main()

and

int main(int argc, char* argv[])

which is equivalent to

int main(int argc, char** argv)

It is also worth noting that in C++, int main() can be left without a
return-statement, at which point it defaults to returning 0. This is also 
true
with a C99 program. Whether return 0; should be omitted or not is open to 
debate. The range of valid C program main signatures is much greater.

Efficiency is not an issue with the main function. It can only be entered and left once (marking the program's start and termination) according to the C++ standard. For C, re-entering main() is allowed, but should be avoided.
Comment

what do I return in int main() function c++

int main() {
  return 1;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: loop through a vector in c++ 
Cpp :: c++ return multiple values 
Cpp :: vector of strings initialization c++ 
Cpp :: slice std::array cpp 
Cpp :: c++ length of char array 
Cpp :: c++ vector loop delete 
Cpp :: int to string c++ 
Cpp :: footnote appears in the middle latex 
Cpp :: c++ typeid 
Cpp :: change integer to string c++ 
Cpp :: c++ vector pop_back 
Cpp :: round up 2 digits float c++ 
Cpp :: get window position 
Cpp :: docker.io : Depends: containerd (= 1.2.6-0ubuntu1~) E: Unable to correct problems, you have held broken packages 
Cpp :: print 2d array c++ 
Cpp :: c++ do while loop 
Cpp :: how to get the size of a vector in c++ 
Cpp :: std distance 
Cpp :: how to delete a file in cpp 
Cpp :: 2d array c++ 
Cpp :: initialize vector of vector c++ 
Cpp :: how to input a vector when size is unknown 
Cpp :: min in c++ 
Cpp :: cpp absolute value 
Cpp :: pragma cpp 
Cpp :: integer to char c++ 
Cpp :: c detect os 
Cpp :: descending order c++ 
Cpp :: c function as paramter 
Cpp :: joining two vectors in c++ 
ADD CONTENT
Topic
Content
Source link
Name
7+6 =