Archived

This topic is now archived and is closed to further replies.

Pointer = Array;

This topic is 5618 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have two variables which one of them is a global pointer and the other is a local array. char* global_pointer; char local_array[A_VALUE]; How do I save the value in local_array into global_pointer? I can''t just point the pointer on the array because the pointer is global and I need it outside. If local_array = "hello" then global_pointer = "hello".

Share this post


Link to post
Share on other sites
A pointer isn''t storage, it points to storage. Once the auto variable goes out of scope, so does the values it stores and then there''s nothing to point to. You can declare the local array static. That will give it global duration. Or you can declare the global variable as char (not char *) and then copy the auto variable value into the global eg. g_CharVar = local_array[A_VALUE];

Share this post


Link to post
Share on other sites