| |

VerySource

 Forgot password?
 Register
Search
View: 1175|Reply: 5

About variable initialization

[Copy link]

4

Threads

20

Posts

14.00

Credits

Newbie

Rank: 1

Credits
14.00

 United States

Post time: 2020-3-11 14:00:01
| Show all posts |Read mode
For example, int is initialized to 0
So why is AnsiString type initialization good?
Some books write AnsiString as = ""; others write AnsiString as = NULL;
There are also some structure variables, such as handle variables. Why is this kind of initialization necessary?
Reply

Use magic Report

0

Threads

45

Posts

32.00

Credits

Newbie

Rank: 1

Credits
32.00

 China

Post time: 2020-6-4 13:45:01
| Show all posts
Some books write initialization AnsiString as=""; others write AnsiString as=NULL;

AnsiString a="" is slightly different from AnsiString a=NULL
It can be considered that the former is valuable, the value is empty

The handle is initialized to NULL

The structure directly struct A a={0};
Reply

Use magic Report

4

Threads

20

Posts

14.00

Credits

Newbie

Rank: 1

Credits
14.00

 China

 Author| Post time: 2020-6-8 22:45:01
| Show all posts
Which one is better?
Reply

Use magic Report

0

Threads

14

Posts

10.00

Credits

Newbie

Rank: 1

Credits
10.00

 China

Post time: 2020-6-9 10:45:01
| Show all posts
It doesn't matter what kind of good, habit problems, at least initialization can give you a criterion for later judgment.
Reply

Use magic Report

0

Threads

15

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

Post time: 2020-6-13 18:30:02
| Show all posts
Agree upstairs.
Reply

Use magic Report

0

Threads

7

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

Post time: 2020-6-16 21:30:01
| Show all posts
It does not matter what is initialized to.
But AnsiString ansiTemp = "" is not the same as ansiTemp = NULL.
ansiTemp = "" There is nothing in ansiTemp. The length is 0.
ansiTemp = NULL means that ansiTemp is empty and has a length of 1.
What the initialization looks like only determines how to judge whether it is initialized when the following program runs.
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