What's the difference between declaring and defining?

Asked 1 years ago, Updated 1 years ago, 56 views

What's the difference between declaring and defining? Is it just the difference between having {} and not having it?

c c++ terminology

2022-09-21 16:30

1 Answers

The declaration serves to determine the type of identifier and identifier. The declaration determines whether identifier is a common type such as int, char, object, or a function. A declaration allows the compiler to accept identifier as a reference.

All of the following codes correspond to declarations.

extern int bar;
extern int g(int, int);
double f(int, double);
class foo;

The definition serves to implement the identifier. Linker is used to connect reference and entity. *Definitions can be used with declarations.

The following code is a definition corresponding to the declaration above.

int bar;
int g(int lhs, int rhs) {return lhs*rhs;}
double f(int i, double d) {return i+d;}
class foo {};

There are few restrictions on declaring identifier. The following declarations can be written in both C/C++ without problems. (However, only one of these can be used within the same scope.)

double f(int, double);
double f(int, double);
extern double f(int, double); // the same as the two above
extern double f(int, double);

symbol을 선언해놓고 정의하지 않았을 때에는 linker가 해당 symbol을 알려주고 symbol linker when a justice many times redundant because it is unknown what definitions should be link symbol to tell the .


2022-09-21 16:30

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.