alright some people wonder what's the different between these two ,syntax
int main()
{
return x;
}
void main()
{
return ;
}
the int main() or void main() part is known as function header,
and the int or void represents as return value,if that's int ,it means the function returns integer type of value ,else if it's void ,that is not return any value ,so you can just ignore the return keyword at end of use alone.
and the main part is known the function name and variables,pointers,arrays,or anything inside the parenthesis are known as parameters so you pass arguments to those parameters.
consider the main part ,that's the main function of the cpp any file and whenever the compiler compiles anything ,it finds that first also the software run from the main function,it doesn't matter how much of codes put above it ,when you return something to main function ,it will pass to the OS.!
and if that's 0 means the program return a signal to tell OS ,the program stopped,so that's how the OS knows the program stops or not.
you can also use give commands from outside to the program by using parameters of main function
int main(int size, char* pName[])
{
cout << pName << endl;
system("pause");
return 0;
}
so the size variable is the size of pointer char variable's string ,remember the pName is a pointer char ,it means you need to declare it as an array also in this case the pointer can directly take a string and IT WILL NOT TAKE AN ADDRESS.!!
now in DOS prompt type any string with the program's name so you can see it in the program.
example
C:\ProgramName.exe "Code Call"
remember the SIZE Is not the number of characters.!!
IT'S NUMBER OF WORDS IN THE STRING THAT U TYPE.!!! :w00t:
IF U TYPE ANYTHING WITHIN DOUBLE QUOTATIONS THEN THAT WILL ALSO BE CONSIDERED AS
ONE WORD
example
"code call" / codecall ==> 1
"code call" forum / codecall forum =>2
Edited by UbuntuX, 08 August 2010 - 07:32 AM.


Sign In
Create Account

This topic is locked

Back to top










