| |

VerySource

 Forgot password?
 Register
Search
View: 569|Reply: 3

Ask a const question

[Copy link]

1

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-3-2 15:30:01
| Show all posts |Read mode
I defined the constant string const char * c = "123456";
string s1 ("test");
c = s1.c_str ();
Why is there a constant modifier const before I can change the contents of c
Reply

Use magic Report

0

Threads

63

Posts

43.00

Credits

Newbie

Rank: 1

Credits
43.00

 China

Post time: 2020-5-13 09:15:01
| Show all posts
C here is not a constant, it must be written as const char * const c = "123456";
Reply

Use magic Report

0

Threads

17

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

Post time: 2020-5-13 09:45:01
| Show all posts
You are pointing to a const object, and the change is a pointer, where the pointer is not const
Reply

Use magic Report

2

Threads

54

Posts

34.00

Credits

Newbie

Rank: 1

Credits
34.00

 China

Post time: 2020-5-13 14:45:01
| Show all posts
const char * const c = "123456";
So that c is const
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