I have forgotten
my Password

Or login with:

  • Facebookhttp://facebook.com/
  • Googlehttps://www.google.com/accounts/o8/id
  • Yahoohttps://me.yahoo.com
Index » Programming » C/C++ »

Need Help?

engjay\′s Photo
4 May 10, 9:52AM
(1 reply)
Need Help?
Hi there

i have some questions in C program and i straggled to find right answer.

1- What is the different between void main and in main(void). 2- what is parameter in c program? 3-In loop what the different between ++i And i++? 4- what the benfits of the loop(for and while)and when we need to use them?

I know it seems to be stupid questions for some people but i am new in c program.

Thanks
CodeCogs\′s Photo
16 May 10, 7:56PM
In answer to your points:

  • void main() and int main(void) are for all practical purposes identical. On Unix/Linux machine, all programs need to return something, so most code is written using int main(). As for the void, well that should never be necessary, but some compilers require it.
  • In the following code a and b are parameters
int fred(int a, int b) { .. }
  • There is no different between ++i and i++ in a for loop. i.e. the following loops are identical:
for(int i=0; i<10; i++) { ... } 
for(int i=0; i<10; ++i) { ... }
In case someone argues that ++i is faster than i++, well thats wrong. All compilers are smart enough to optimise for this. If your really interested in speed, then you should always count downwards, as in
for(int i=9; i>=0; i--) { ... }
Currently you need to be logged in to leave a message.