Getting stack value from function [duplicate]

Multi tool use
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
c++ arrays char pass-by-reference
marked as duplicate by Peter Ruderman, il_raffa, πάντα ῥεῖ
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.
|
show 1 more comment
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
c++ arrays char pass-by-reference
marked as duplicate by Peter Ruderman, il_raffa, πάντα ῥεῖ
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 thearr
array ceases to exist as soon as thegetMsg
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 putprintf("%sn", msg);
right beforereturn 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
|
show 1 more comment
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
c++ arrays char pass-by-reference
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
c++ arrays char pass-by-reference
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, πάντα ῥεῖ
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, πάντα ῥεῖ
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 thearr
array ceases to exist as soon as thegetMsg
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 putprintf("%sn", msg);
right beforereturn 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
|
show 1 more comment
Please elaborate your code, it's somewhat unclear what you're trying to achieve, but anyway thearr
array ceases to exist as soon as thegetMsg
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 putprintf("%sn", msg);
right beforereturn 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
|
show 1 more comment
0
active
oldest
votes
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
iuQaSo8UVpfXn1gGwpk5VrRhYV824Y6PLLlpMDN7IWhjls4KGLRc1Iusv3t,pS9v8rbvdm,m,y,d7,eg2R
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 thegetMsg
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 beforereturn 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