| |

VerySource

 Forgot password?
 Register
Search
View: 1195|Reply: 8

I am a beginner, what is the difference between declaration and definition, thank you

[Copy link]

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-11-30 19:30:02
| Show all posts |Read mode
I’m a beginner, I often read the book and say the statement and the definition
It seems that the two are similar. Is there any difference? ? Specifically, thank you
Reply

Use magic Report

0

Threads

8

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

Post time: 2020-11-30 19:45:01
| Show all posts
Personal habits are similar, but when using the extern keyword, it is fame rather than definition
Reply

Use magic Report

1

Threads

5

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-11-30 20:15:01
| Show all posts
class a
{
void test(); //declaration
}

void a::test() //define
{
}

The declaration just means that there is such a function, and the definition implements this function!
Reply

Use magic Report

1

Threads

27

Posts

23.00

Credits

Newbie

Rank: 1

Credits
23.00

 China

Post time: 2020-11-30 23:45:01
| Show all posts
The declaration of a variable is actually an empty thing. In C++, it is equivalent to an empty pointer. It does not point to anything and has no practical meaning. In fact, it is quite similar to an object. For things in a class, whether it is a function or a variable, it must be accessed through the object, except for the static ones. So, the variable (actual value) in the inner cluster is called through the object of reputation
The definition of a variable is different. It specifies a certain space in the inner cluster, such as 122103, which has a certain practical significance.
The two concepts are related
Reply

Use magic Report

1

Threads

27

Posts

23.00

Credits

Newbie

Rank: 1

Credits
23.00

 China

Post time: 2020-12-1 00:15:01
| Show all posts
In fact, in general, the declaration is to let the compiler know that there is this thing, and the definition is to allocate space for this thing
Reply

Use magic Report

0

Threads

5

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-12-1 08:15:01
| Show all posts
Definition is also a kind of declaration,
But after the definition, the memory of this thing is declared. . .
Reply

Use magic Report

1

Threads

9

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2020-12-1 09:30:01
| Show all posts
I suggest you buy a book in C language
Take a look, such as "C Language Reference Manual"
Reply

Use magic Report

0

Threads

5

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-12-1 10:15:01
| Show all posts
The statement is that there is this thing, I will not allocate memory space for you
The definition shows that this thing exists, and I allocate the space to you
Reply

Use magic Report

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2020-12-1 10:30:01
| Show all posts
Haha very specific, thank you everyone for your help
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list