What is the function of 'main' in 'c' programming?
what is the function of 'main' in 'c' programming?
int main (void)
In the above statement, void represent??
int main (void)
In the above statement, void represent??
Replies
-
Neeraj Sharma
void represents that main function is not taking any argument while its execution. You can even skip that void and write main(). main takes two arguments like main(int argc, char *argv[])aarthivgwhat is the function of 'main' in 'c' programming?
int main (void)
In the above statement, void represent??
where argc is the counter that counts the number of arguments passed to main and argv means argument vector which stores all the arguments passed in the form of a character array -
aarthivgI remember using as such: void main()
whats the difference between these statement.
void main()
int main(void) -
aarthivg
Is arguments and parameter, both mean the sameNick_Sharmavoid represents that main function is not taking any argument while its execution. You can even skip that void and write main(). main takes two arguments like main(int argc, char *argv[])
where argc is the counter that counts the number of arguments passed to main and argv means argument vector which stores all the arguments passed in the form of a character array -
Anoop Kumarvoid main() means... this function is not returning any value.
int void main() is a illegal declaration .
either it could be int main() , which must have a integer type return statement as last line of function
or another type of return. -
aarthivg
sorry, its int main(void)ianoopvoid main() means... this function is not returning any value.
int void main() is a illegal declaration .
either it could be int main() , which must have a integer type return statement as last line of function
or another type of return. -
Anoop Kumar
that means main function is not taking any argument and will return a integer type value.aarthivgsorry, its int main(void)
why should not you make some programs about your doubts.compiler itself will tell you . -
aarthivg
ya I have too. I don't have the softwareπianoopthat means main function is not taking any argument and will return a integer type value.
why should not you make some programs about your doubts.compiler itself will tell you . -
Neeraj Sharma
Yeah they are same...!aarthivgIs arguments and parameter, both mean the same -
Dancer_Engineer
Take a look at this video:aarthivgya I have too. I don't have the softwareπ
-
silverscorpionThe function definition in C is like this..
Here, return-type can be of any data-type, like int or char etc.. It can also be "void" which means that function doesn't return anything.function-name( )
In the list of arguments, you can give one or more arguments (or) 'parameters' to the function. If the function doesn't take any arguments, you can specify that by writing 'void' in place of the arguments. Hence 'function-name(void)'. But usually, if a function doesn't take any arguments, it's name is simply followed by a set of parentheses, like so.. "function-name()" -
aarthivgreturn statement means?
-
Neeraj Sharma
return type depicts the type of value that your function returns. return statement returns a value to the caller function. Consider following programaarthivgreturn statement means?
main() { int c; c=sum(); printf("%d",c); return 0; } int sum() { int a=1,b=2; return(a+b); }
In the above program, return(a+b) is called return statement as it returns an integer value to the calling function that is main. Now as an integer value is returned, there must be a variable to hold the returned data and even that must be of the same type as the type of value returned i.e. int in this case.. -
herreyWell how differ main from array?
I know in C++ array are so important so can you explain its difference? -
Neeraj Sharma
There is no match between main and array. They are two different things all together. main() marks the beginning point of execution of a program whereas array is simply a collection of objects of same type which are referred under a same name whose memory is allocated statically. main() is a function whereas array is a collection of elements of the same data typeherreyWell how differ main from array?
I know in C++ array are so important so can you explain its difference? -
aarthivg
return 0 implies ?Nick_Sharmareturn type depicts the type of value that your function returns. return statement returns a value to the caller function. Consider following program
main() { int c; c=sum(); printf("%d",c); return 0; } int sum() { int a=1,b=2; return(a+b); }
In the above program, return(a+b) is called return statement as it returns an integer value to the calling function that is main. Now as an integer value is returned, there must be a variable to hold the returned data and even that must be of the same type as the type of value returned i.e. int in this case.. -
Neeraj SharmaAs I have not specified any return type for main, by default it will be int. So as the system calls the main function, you are just returning a dummy integer value. It doesn't do anything..
-
aarthivgthen getch() is used for?
-
Neeraj Sharma
getch() is used to read a character from keyboard...aarthivgthen getch() is used for? -
aarthivg#include
#include
int main()
{
int a,b,sub;
printf(" enter the value of a");
scanf("%d",&a);
printf("enter the value of b");
scanf("%d",&b);
sub=a-b;
printf(" %d",&sub);
return 0;
}
just tried out a simple program.... but cant able to get the output... whats wrong in it
for 3-2 ... getting output as 9016 -
Neeraj Sharma
Here is the mistake. & is called address operator. So when you are printing &sub, you are printing the address at which the result is stored and not the result. replace the above line withaarthivgprintf(" %d",&sub);
printf("%d",sub);
This will make your program work perfectly.. -
aarthivg
ya...thanks... got itNick_SharmaHere is the mistake. & is called address operator. So when you are printing &sub, you are printing the address at which the result is stored and not the result. replace the above line with
printf("%d",sub);
This will make your program work perfectly.. -
aarthivgwhat is the use of SYSTEM("PAUSE") command
-
Neeraj Sharma
System() is used to call OS functions. System("pause") causes the DOS output screen to be held. It does the same function as getch() when used as the last line in program. If you don't write getch() or System("pause") in the earlier versions of C then the black screen just flashes and then disappears. Then you must press alt+f5 to view the output. System("pause") and getch() prevents the flashing of screen and holds it till a character is enteredaarthivgwhat is the use of SYSTEM("PAUSE") command -
aarthivgIs there a header file defined Boolean constant as stdbool.h?
#include
#include
int main(void)
{
bool x=true;
bool y=false;
printf(" the boolean values are %d %d\n",x,y);
return 0;
} -
aarthivgIs there a header file defined Boolean constant as stdbool.h?
#include
#include
int main(void)
{
bool x=true;
bool y=false;
printf(" the boolean values are %d %d\n",x,y);
return 0;
}
help me out
Tagging #-Link-Snipped-# #-Link-Snipped-# #-Link-Snipped-# -
Anoop KumarI have no idea about it... π
-
Neeraj SharmaSame here. No idea. Tried searching it but with no significant answer.. Anyway the above program is not working in Turbo C++ 4.5. I downloaded stdbool.h and tried but then also there are errors...
-
Abhishek RawalSorry for bumping in old thread (Killing time);
Yes, there's a header file defined boolean constant as stdbool.h
Using emacs editor & GCC 4.7 -
sulochana anandthe execution of program starts from main function.
-
bithamangin 11th line u should write as
printf("%d",sub);
only u put & before sub so it displays the address of sub -
Sanyam Khuranaaarthivgwhat is the function of 'main' in 'c' programming?
int main (void)
In the above statement, void represent??
The main function has two basic functions :-
1) It allocates the memory for program.
2) It guides the compiler, that compilation will start from the main function.
In the statement
int main (void); (always terminate a statement with a semicolon) π
void represents that the function do not takes any arguments.
The statement is same as
int main(); π
If you still have any doubts, feel free to ask π -
rahul69
Not always!!π Actually avoid semicolon in case of loops and conditional statements(ie if blocks)Sanyam Khuranaint main (void); (always terminate a statement with a semicolon) π
eg:int i=0; while (i<10); i++;
. Big Blunder!!ππ -
lit-857int main() return value to whom??
-
lit-857last line should be printf("%d",sub);
-
lit-857aarthivg#include
#include
int main()
{
int a,b,sub;
printf(" enter the value of a");
scanf("%d",&a);
printf("enter the value of b");
scanf("%d",&b);
sub=a-b;
printf(" %d",&sub); //error//
return 0;
}
just tried out a simple program.... but cant able to get the output... whats wrong in it
for 3-2 ... getting output as 9016
line should be printf("%d",sub); -
avii
to the system. Or to the caller.lit-857int main() return value to whom?? -
Sanyam Khurana
haha, yes that's true, I was talking about General statements πrahul69Not always!!π Actually avoid semicolon in case of loops and conditional statements(ie if blocks)
eg:int i=0; while (i<10); i++;
. Big Blunder!!ππ -
lit-857who call the main function
-
Sanyam Khurana
What do you mean?lit-857who call the main function -
Vishal Sharmaianoopvoid main() means... this function is not returning any value.
int void main() is a illegal declaration .
either it could be int main() , which must have a integer type return statement as last line of function
or another type of return.
actually it returns a value.. but its not specific so we call it void.. -
Vishal Sharma
its the operating system...lit-857who call the main function
and main() is always "public" so that it is visible to the OS -
Abhishek Rawal
As per my knowledge, RTE calls the main function & not just OS.Vishal0203its the operating system...
and main() is always "public" so that it is visible to the OS -
lit-857wts RTE and main () return value to whome???
-
Vishal SharmaRTE stands for run-time environment..
main() returns value to RTE itself, indicating its status of execution -
lit-857plz explain it i can't understend
-
Vishal SharmaMeans, if main returns a null value, then the program is executed successfully.. 0 indicates EXIT_ON_SUCCESS
any value other than zero indicates unusual execution.. -
Anand Tamariya
A c program is compiled into assembly code(and finally into binary). The main() function enables the compiler to put the code present in this method as first line in the compiled version - the entry point of the program when you execute it.lit-857plz explain it i can't understend -
Vishal Sharmamain is a function and array is a collection of elements of same data type defined under same name..
no point of getting confused here. -
lit-857wts d/f b/w celloc() and melloc() fn
-
Vishal Sharma
ummm... do you have a text Book to learn C??lit-857wts d/f b/w celloc() and melloc() fn
I think you must refer that.. text books are the first companions. after reading that, still you face problems in understanding, we'll help you -
Jeffrey Arulraj
At the same time please avoid SMS language cause it can lead to misconception among uslit-857wts d/f b/w celloc() and melloc() fn
We are willing to help you more so please be more clear to us
You are reading an archived discussion.
Related Posts
I AM A MCA STUDENT.
hai friends m navin. frm kerala,india... I am doing my engineering in CS...
Name: Syed Ahmed Kamal
*Engineering Field: Electronics
Location: Karachi,Pakistan
*Occupation: (Student of third year Electronics Engineering at Sir Syed University)
*I joined CrazyEngineers because: To let to know about new...
Entrance exam is a part of every engineer's life. Here's a comic take by Absolute Zero on entrance exams.
hello Engineers !
I am a student of electronics and communication engineering!
i will graduate hopefully , i year or 2 from now. (hopes)
Im here to look better ideas...