Getting stack value from function [duplicate]












0
















This question already has an answer here:




  • How do I modify a pointer that has been passed into a function in C?

    5 answers



  • How to return a char array created in function?

    4 answers




void getMsg(char *msg)
{
char arr[255] = "msg";
msg = arr;
}

int main()
{
char *msg= nullptr;
getMsg(msg);
std::cout<<msg; //Output: msg

return 0;
}


Hi all.
I didn't find exact answer, sorry if it is repeated.



I want to have get char array from function to pointer which is passing as argument. Is it correct? If it not, how I could do this without allocate memory dynamicly?
Thanks










share|improve this question















marked as duplicate by Peter Ruderman, il_raffa, πάντα ῥεῖ c++
Users with the  c++ badge can single-handedly close c++ questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 22 '18 at 19:20


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
















  • Please elaborate your code, it's somewhat unclear what you're trying to achieve, but anyway the arr array ceases to exist as soon as the getMsg function finishes. Also have a look at this SO article

    – Jabberwocky
    Nov 22 '18 at 16:28













  • Please clarify what output you expect if you put printf("%sn", msg); right before return 0;.

    – Jabberwocky
    Nov 22 '18 at 16:30











  • I want have in msg pointer msg from function. And in my case it is needed to get it from array allocate on stack in function

    – unknowed
    Nov 22 '18 at 16:31











  • I expect msg in output

    – unknowed
    Nov 22 '18 at 16:31











  • @unknowed OK, please edit your question and put all clarifications there. You need to read the first comment.

    – Jabberwocky
    Nov 22 '18 at 16:33


















0
















This question already has an answer here:




  • How do I modify a pointer that has been passed into a function in C?

    5 answers



  • How to return a char array created in function?

    4 answers




void getMsg(char *msg)
{
char arr[255] = "msg";
msg = arr;
}

int main()
{
char *msg= nullptr;
getMsg(msg);
std::cout<<msg; //Output: msg

return 0;
}


Hi all.
I didn't find exact answer, sorry if it is repeated.



I want to have get char array from function to pointer which is passing as argument. Is it correct? If it not, how I could do this without allocate memory dynamicly?
Thanks










share|improve this question















marked as duplicate by Peter Ruderman, il_raffa, πάντα ῥεῖ c++
Users with the  c++ badge can single-handedly close c++ questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 22 '18 at 19:20


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
















  • Please elaborate your code, it's somewhat unclear what you're trying to achieve, but anyway the arr array ceases to exist as soon as the getMsg function finishes. Also have a look at this SO article

    – Jabberwocky
    Nov 22 '18 at 16:28













  • Please clarify what output you expect if you put printf("%sn", msg); right before return 0;.

    – Jabberwocky
    Nov 22 '18 at 16:30











  • I want have in msg pointer msg from function. And in my case it is needed to get it from array allocate on stack in function

    – unknowed
    Nov 22 '18 at 16:31











  • I expect msg in output

    – unknowed
    Nov 22 '18 at 16:31











  • @unknowed OK, please edit your question and put all clarifications there. You need to read the first comment.

    – Jabberwocky
    Nov 22 '18 at 16:33
















0












0








0









This question already has an answer here:




  • How do I modify a pointer that has been passed into a function in C?

    5 answers



  • How to return a char array created in function?

    4 answers




void getMsg(char *msg)
{
char arr[255] = "msg";
msg = arr;
}

int main()
{
char *msg= nullptr;
getMsg(msg);
std::cout<<msg; //Output: msg

return 0;
}


Hi all.
I didn't find exact answer, sorry if it is repeated.



I want to have get char array from function to pointer which is passing as argument. Is it correct? If it not, how I could do this without allocate memory dynamicly?
Thanks










share|improve this question

















This question already has an answer here:




  • How do I modify a pointer that has been passed into a function in C?

    5 answers



  • How to return a char array created in function?

    4 answers




void getMsg(char *msg)
{
char arr[255] = "msg";
msg = arr;
}

int main()
{
char *msg= nullptr;
getMsg(msg);
std::cout<<msg; //Output: msg

return 0;
}


Hi all.
I didn't find exact answer, sorry if it is repeated.



I want to have get char array from function to pointer which is passing as argument. Is it correct? If it not, how I could do this without allocate memory dynamicly?
Thanks





This question already has an answer here:




  • How do I modify a pointer that has been passed into a function in C?

    5 answers



  • How to return a char array created in function?

    4 answers








c++ arrays char pass-by-reference






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 '18 at 21:55







unknowed

















asked Nov 22 '18 at 16:13









unknowedunknowed

11




11




marked as duplicate by Peter Ruderman, il_raffa, πάντα ῥεῖ c++
Users with the  c++ badge can single-handedly close c++ questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 22 '18 at 19:20


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






marked as duplicate by Peter Ruderman, il_raffa, πάντα ῥεῖ c++
Users with the  c++ badge can single-handedly close c++ questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 22 '18 at 19:20


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.















  • Please elaborate your code, it's somewhat unclear what you're trying to achieve, but anyway the arr array ceases to exist as soon as the getMsg function finishes. Also have a look at this SO article

    – Jabberwocky
    Nov 22 '18 at 16:28













  • Please clarify what output you expect if you put printf("%sn", msg); right before return 0;.

    – Jabberwocky
    Nov 22 '18 at 16:30











  • I want have in msg pointer msg from function. And in my case it is needed to get it from array allocate on stack in function

    – unknowed
    Nov 22 '18 at 16:31











  • I expect msg in output

    – unknowed
    Nov 22 '18 at 16:31











  • @unknowed OK, please edit your question and put all clarifications there. You need to read the first comment.

    – Jabberwocky
    Nov 22 '18 at 16:33





















  • Please elaborate your code, it's somewhat unclear what you're trying to achieve, but anyway the arr array ceases to exist as soon as the getMsg function finishes. Also have a look at this SO article

    – Jabberwocky
    Nov 22 '18 at 16:28













  • Please clarify what output you expect if you put printf("%sn", msg); right before return 0;.

    – Jabberwocky
    Nov 22 '18 at 16:30











  • I want have in msg pointer msg from function. And in my case it is needed to get it from array allocate on stack in function

    – unknowed
    Nov 22 '18 at 16:31











  • I expect msg in output

    – unknowed
    Nov 22 '18 at 16:31











  • @unknowed OK, please edit your question and put all clarifications there. You need to read the first comment.

    – Jabberwocky
    Nov 22 '18 at 16:33



















Please elaborate your code, it's somewhat unclear what you're trying to achieve, but anyway the arr array ceases to exist as soon as the getMsg function finishes. Also have a look at this SO article

– Jabberwocky
Nov 22 '18 at 16:28







Please elaborate your code, it's somewhat unclear what you're trying to achieve, but anyway the arr array ceases to exist as soon as the getMsg function finishes. Also have a look at this SO article

– Jabberwocky
Nov 22 '18 at 16:28















Please clarify what output you expect if you put printf("%sn", msg); right before return 0;.

– Jabberwocky
Nov 22 '18 at 16:30





Please clarify what output you expect if you put printf("%sn", msg); right before return 0;.

– Jabberwocky
Nov 22 '18 at 16:30













I want have in msg pointer msg from function. And in my case it is needed to get it from array allocate on stack in function

– unknowed
Nov 22 '18 at 16:31





I want have in msg pointer msg from function. And in my case it is needed to get it from array allocate on stack in function

– unknowed
Nov 22 '18 at 16:31













I expect msg in output

– unknowed
Nov 22 '18 at 16:31





I expect msg in output

– unknowed
Nov 22 '18 at 16:31













@unknowed OK, please edit your question and put all clarifications there. You need to read the first comment.

– Jabberwocky
Nov 22 '18 at 16:33







@unknowed OK, please edit your question and put all clarifications there. You need to read the first comment.

– Jabberwocky
Nov 22 '18 at 16:33














0






active

oldest

votes

















0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes

Popular posts from this blog

404 Error Contact Form 7 ajax form submitting

How to know if a Active Directory user can login interactively

TypeError: fit_transform() missing 1 required positional argument: 'X'