Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>1) All functions must be declared in their function prototype, and later on, in their definition. Why don't we have to declare the main() function in a prototype first?</p> </blockquote> <p>Not true. Simple example:</p> <pre><code>void foo(){} //definition int main() { foo(); return 0; } </code></pre> <p>Only when one function is called but the definition isn't seen yet, a declaration is required. That will never happen to <code>main</code> since it is the starup of the program.</p> <hr> <blockquote> <p>2) Why do we have to use int main() instead of void main()?</p> </blockquote> <p>Because the standard says so. (To be more precise, it's true on a hosted environment, which is usually the case)</p> <blockquote> <p><strong>C99 5.1.2.2.1 <em>Program startup</em></strong></p> <p>The function called at program startup is named <code>main</code>. The implementation declares no prototype for this function. It shall be defined with a return type of <code>int</code> and with no parameters:</p> <pre><code>int main(void) { /* ... */ } </code></pre> <p>or with two parameters (referred to here as <code>argc</code> and <code>argv</code>, though any names may be used, as they are local to the function in which they are declared):</p> <pre><code>int main(int argc, char *argv[]) { /* ... */ } </code></pre> <p>or equivalent; or in some other implementation-defined manner.</p> </blockquote> <hr> <blockquote> <p>3) What does return 0 exactly do in the main() function? What would happen if I wrote a program ending the main() function with return 1, for example?</p> </blockquote> <p>The return value indicates the result of the program. Usually <code>0</code> indicates success while other values indicates different kinds of failure.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload