Loading....
Coupon Accepted Successfully!

 

Question 1

Whats the prototype of main()? Can main() return a structure?

The right declaration of main() is


int main(void)

or 

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

or 

int main(int argc, char *argv[], char *env[]) //Compiler dependent, non-standard C.





In C, main() cannot return anything other than an int.Something like


void main()


is illegal. There are only three valid return values from main() - 0, EXIT_SUCCESS, and EXIT_FAILURE, the latter two are defined in .



Something like this can cause unpredicted behavior


struct mystruct {
  int value;
  struct mystruct *next;
}

main(argc, argv)
{ ... }



Here the missing semicolon after the structure declaration causes main to be misdeclared.


Question 2

Is exit(status) equivalent to returning the same status from main()?


No.

The two forms are not equivalent in a recursive call to main().


Question 3

Can main() be called recursively?


Yes


main()
{
    main();
}



But this will go on till a point where you get a


Runtime error : Stack overflow.



Question 4

How to print the arguments recieved by main()?


Here is some code


main(int argc, char*argv[])
{
  int i;
  for(i=0; i   {
    printf("\n[%s]\n", argv[i]);
  }
}







Test Your Skills Now!
Take a Quiz now
Reviewer Name