| |

VerySource

 Forgot password?
 Register
Search
Author: 偶素菜鸟

I do n’t understand a question about enrollment, everyone helps

[Copy link]

0

Threads

6

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-5-23 17:15:01
| Show all posts
delete is used to release heap memory
So 1:
char * z = new char [6];
delete [] z;
can

So 2:
z = "abcde";
At this time, because "abcd" is no longer applying for heap memory,
delete [] z
error

Personal opinion, huh !!
Reply

Use magic Report

1

Threads

39

Posts

27.00

Credits

Newbie

Rank: 1

Credits
27.00

 China

Post time: 2020-5-29 10:15:01
| Show all posts
cout << hex <<&z + k << endl;

Change to:
 cout << hex <<&z [k] << endl;
Reply

Use magic Report

0

Threads

6

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-6-10 16:30:01
| Show all posts
zfy010317Brother:
cout<<hex<<&z+k<<endl;

Change to:
cout << hex <<&z[k] << endl;

I didn’t understand how to post spam,
I think at least you have to debug it to have a say
Otherwise, it is easy to mislead everyone

For the second question of the landlord, brotherch1074856is the positive solution
&z+k is an address that makes no sense at all
To get the addresses of all the elements in the array, just remove the address symbol&
Because z itself represents the first address of the array
cout<<hex<<z+k<<endl;
Reply

Use magic Report

0

Threads

5

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-6-17 10:00:01
| Show all posts
Upstairs,zfy010317said that it was right, and it was you who was wrong (you said there was no debugging, did you debug)
Reply

Use magic Report

1

Threads

8

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 Europe

Post time: 2020-6-18 10:30:01
| Show all posts
agree!
Reply

Use magic Report

0

Threads

5

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-6-18 20:15:01
| Show all posts
Say Sorry tosun88888, you are also right, so is Space Hero:


    char z[]= "abcde";
    for(int k=0; k<5; k++)
    {
        cout<<hex<<(int*)(z+k)<<endl;//After testing, to output the address, the char* type address must be converted to int*, otherwise the characters will be output.
        cout<<hex<<(int*)&z[k]<<endl;//Space Hero
        cout<<z[k]<<endl;
    }
Reply

Use magic Report

0

Threads

55

Posts

44.00

Credits

Newbie

Rank: 1

Credits
44.00

 Invalid IP Address

Post time: 2020-6-19 17:15:02
| Show all posts
Landlord cout<<typeid(&z+k).name()<<endl;
cout<<typeid(*(z+k)).name()<<endl;
Just try and you will find out.
Reply

Use magic Report

1

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

 Author| Post time: 2020-7-17 13:45:01
| Show all posts
Thank you so much.
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