Connecting Tech Pros Worldwide Help | Site Map

Re: Store int* array

 
LinkBack Thread Tools Search this Thread
  #1  
Old August 27th, 2008, 08:25 AM
Obnoxious User
Guest
 
Posts: n/a
Default Re: Store int* array

On Wed, 27 Aug 2008 00:07:35 -0700, MN wrote:
[snip]
Quote:
>
for (i = 0; i < in2; i++)
{
if (i == 0)
{
Quote:
//printf("- %d\n", &view_var1[i]);
printf("- %d\n",var1[i]);
}
Quote:
>
else
{
Quote:
//printf("%d %d\n", i-1, &view_var1[i]);
> printf("%d %d\n", i-1, var1[i]);
}
Quote:
}
return 0;
>
}
>
int* function(int in1, int in2)
{
int i = 0;
if (var1 != NULL)
free(var1);
var1 = (int*)malloc (sizeof(int*)* in2);
>
>
for (i = 0; i < in2; i++)
{
if (i == 0)
var1 [i] = 0;
else
{
if (i == 1)
var1[i]= 1;
else
var1[i] = var1[i-1]*2+in1;
}
}
return (var1[in2]);
}
>
The return type is int* but here you return int. The correct
way would be to write:

return var1+in2;

But then again, that just returns a pointer pointing beyond the
allocated array. I'm guessing you actually want the beginning
of the array:

return var1;

--
OU

  #2  
Old August 27th, 2008, 08:35 AM
MN
Guest
 
Posts: n/a
Default Re: Store int* array

Thanks for your help.
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.