dear friends plz clarify my doubt
we know that there are three aspects regarding function
1.function declaration
2.function call
3.function definition
in c,c++ program at the start we write
main()
{
...;
...;
}
now my question is
is this a function declaration or definition or calling?
if it is a function call why don't we give semicolon after main
since often we write function call as
Ex.
swap();
add();
then why not main();
5 1269 Banfa 9,065
Expert Mod 8TB
this is a function definition. The function call is made from with-in the c-start-up code provided by the compiler writer. I do not think that main is declared anywhere.
From what I know of the subject, the main reason for a function declaration is to let your compiler know that the function exists. If you didn't declare a function, but still had the definitions somewhere below your main, the compiler may get confused and not recognize these functions when it tries to compile main(). I'm not sure, but I think you could replace the function declarations at the beginning of your program with the full definition, so that the main() function recognizes its existance and already has the code.
this is a function definition. The function call is made from with-in the c-start-up code provided by the compiler writer. I do not think that main is declared anywhere.
THANKS FOR THE REPLY.
you mentioned that main is not declared.
i agree with you in case of C .
As in C function declaration is optional but as far as C++ is concerned
function declaration is must.
so how it is possible for compiler to compile program without declaration of function in C++.
From what I know of the subject, the main reason for a function declaration is to let your compiler know that the function exists. If you didn't declare a function, but still had the definitions somewhere below your main, the compiler may get confused and not recognize these functions when it tries to compile main(). I'm not sure, but I think you could replace the function declarations at the beginning of your program with the full definition, so that the main() function recognizes its existance and already has the code.
THANKS FOR THE REPLY.
you mentioned that main is not declared.
i agree with you in case of C .
As in C function declaration is optional but as far as C++ is concerned
function declaration is must.
so how it is possible for compiler to compile program without declaration of function in C++.
--------------------------------------------------------------------------------
Banfa 9,065
Expert Mod 8TB
It is possible because the piece of code that calls main is not (normally) released to you as source code (except for reference) but is realeased precompiled as binary code. The definition is only required for compilation of the function call not the function definition.
I have checked my MSVC++ installation and main is predeclared, but only in an internal header that appears to be only included into library source code.
The rule is C++ is not that a function must be predeclared. It is that a function can't not be called before it has been defined or predeclared. Which is subtly different.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Steven T. Hatton |
last post by:
This is a purely *hypothetical* question. That means, it's /pretend/,
CP. ;-)
If you were forced at gunpoint to put all your code in classes, rather than
in namespace scope (obviously classes...
|
by: Steven T. Hatton |
last post by:
The short sample program listed below has some features that I find to be
bad style. In particular, they fail to communicate the connection between
names used in this program and the location in...
|
by: Sokar |
last post by:
I have my main function set up as
int main(int argv, char *argv)
so taht i can read in a variable which is passed to the program on the
command line. The problem is that main calls other...
|
by: CSharpNewBie |
last post by:
Hi
I am creating a Winform application and I need help. Let me explain my
problem
This is what i do on startup, I create a form (a Login screen) at runtime
and that will ask user to enter a...
|
by: Legendary Pansy |
last post by:
Hello, I'm trying to accomplish the impossible by trying to do something equivalent of this example found here
http://www.c-sharpcorner.com/Code/2003/Dec/DialogTutorial.as
Starting with "Listing...
|
by: Jim |
last post by:
Hi,
I have created an import module. And would like to access a function
from the main script, e.g.,
file abc.py:
###################
def a():
m()
return None
|
by: ravi |
last post by:
Hello everybody,
I am writing a small application which does some work before the user
main function starts execution.
I am trying to #define the main function.
But the problem is that,
|
by: suva |
last post by:
Hi,
What is the precise problem for which we cant declare main() as
static. I know there is no reason to do so but still I wish to know
the precise technical problem for which it is disallowed.
|
by: nick |
last post by:
Does anyone know the file where the main function is defined?
thanks
|
by: Bill Woodruff |
last post by:
Visual Studio 2005, .NET FrameWork 2.0, C#, WinForms Application
Hi,
I've read the recent posts by and to 'Thunderbird' (and learned a lot,
thanks, from the usual masters Skeet and Paladino,...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |