Passing by reference question


 
Thread Tools Search this Thread
Top Forums Programming Passing by reference question
# 1  
Old 05-17-2011
Passing by reference question

Hello All,

I have a question in the following sample code:

If I am passing a reference of a variable, will the dynamic allocation happen in which it is passed?

Will the dynamic allocation will actually change the memory contents of char array "arr"?

Code:
int main()
{
 
char *arr;
 
arr = (char*) malloc(15);
 
fxn(&arr);
 
}
 
int fxn(char** i)
{
 
//allocated memory: will this change the memory of char array "arr"?
 
*i = (char*) malloc(25);
 
//sm code
 
}

Thank you everyone in advance.

Last edited by mind@work; 05-17-2011 at 10:56 AM..
# 2  
Old 05-17-2011
Yes, it will.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Get last reference date

Hi, Could you please help me to get last reference date in Unix, in Unix we maintain SAS7BDAT files. Is there any command or script to get the info, Thank you. (2 Replies)
Discussion started by: subbarao12
2 Replies

2. Shell Programming and Scripting

General question about passing variables among shell scripts

So this is something I've been wondering how to do for a while. Suppose I have two shell scripts a.sh and b.sh script a does some function and outputs to a varable $x . I would then like to take $x into the second function, b.sh, and do a function on it and create some output. So how do you pass... (3 Replies)
Discussion started by: viored
3 Replies

3. Shell Programming and Scripting

Perl de-reference code reference variable

Guys, May i know how can we de reference the code reference variable.? my $a = sub{$a=shift;$b=shift;print "SUM:",($a+$b),"\n";}; print $a->(4,5); How can we print the whole function ? Please suggest me regarding this. Thanks for your time :) Cheers, Ranga :) (0 Replies)
Discussion started by: rangarasan
0 Replies

4. Shell Programming and Scripting

Reading a string and passing passing arguments to a while loop

I have an for loop that reads the following file cat param.cfg val1:env1:opt1 val2:env2:opt2 val3:env3:opt3 val4:env4:opt4 . . The for loop extracts the each line of the file so that at any one point, the value of i is val1:env1:opt1 etc... I would like to extract each... (19 Replies)
Discussion started by: goddevil
19 Replies

5. Programming

Passing Pointers by reference in C++ Problem

Hello All, I am having this issue...where I am actually having hard time understanding the problem: The code is as follows: #include<iostream.h> void fxn(char*** var) { int i =4; *var = (char**)malloc(i*sizeof(char*)); for(int j =0; j<4; j++) { *var = "name"; cout<<*var;... (6 Replies)
Discussion started by: mind@work
6 Replies

6. Shell Programming and Scripting

Symbol reference

Hi, test -d .ssh || mkdir .ssh && chmod 700 .ssh The command has couple of symbols, could someone redirect me to the link, where i can understand their significance. Thanks, John (1 Reply)
Discussion started by: john_prince
1 Replies

7. Shell Programming and Scripting

Question on passing multiple parameters in if

Hi All, My target is to find the list of orphan processes running and i issue the below command with some exception ids. ps -ef | egrep -v "root|system|admin" | awk '{if ($3 == 1) print $1",\t"$2",\t"$3}' but this will exclude the process having the word 'root' and executing under different... (1 Reply)
Discussion started by: Arunprasad
1 Replies

8. Shell Programming and Scripting

Newbie Question: passing a variable into java from script?

I'm currently working on my second ever ksh script! So I apologize if this is a stupid question - I've searched the forum and on google and haven't seen anything :confused: I'm running my script with an input at startup that variable determines a couple of other values(int) that I store into... (1 Reply)
Discussion started by: Cailet
1 Replies

9. UNIX for Dummies Questions & Answers

Question in reference to the pipe |

My question is can you use the pipe more than one time in the same command line? By the way I am new to UNIX. Thanks in advanced! (3 Replies)
Discussion started by: elkoreanopr
3 Replies
Login or Register to Ask a Question