| | |
return array to main
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
C Syntax (Toggle Plain Text)
int** foo() { int i; int** array = malloc(100 * sizeof(int *)); for(i = 0; i < 100; i++) array[i] = malloc(20 * sizeof(int)); // allocate 20 integers return array; } int main() { int ** array = foo(); }
Last edited by Ancient Dragon; Mar 20th, 2009 at 7:45 am.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
for simplification returned array will be of type:
or u can modify above function to get variable 2D array:
same result.
c Syntax (Toggle Plain Text)
int array[100][20] ;
c Syntax (Toggle Plain Text)
int** foo(int row, int col) { int i; int** array = malloc(row * sizeof(int *)); for(i = 0; i < 100; i++) array[i] = malloc(col * sizeof(int)); // allocate 20 integers return array; } int main() { int ** array = foo(100,20); }
Last edited by Narue; Mar 20th, 2009 at 12:11 pm. Reason: added code tags
When you think you have done a lot, then be ready for YOUR downfall.
![]() |
Similar Threads
- (reformatted) How to return Multi-Dimensional Arrays (C++)
- return 2d array to caller from public class function (C++)
- Return Array from C++ (C++)
- How to Return Multidimensional Arrays (C++)
Other Threads in the C Forum
- Previous Thread: decoding auto-generated header #defines
- Next Thread: Hi,Just tell where i am wrong.No need to solve.
| Thread Tools | Search this Thread |
adobe ansi api array arrays asterisks binarysearch calculate centimeter char convert copyimagefile copypdffile cprogramme creafecopyofanytypeoffileinc createcopyoffile csyntax directory dynamic fflush file fork forloop frequency getlasterror givemetehcodez graphics gtkgcurlcompiling hacking hardware highest homework i/o inches incrementoperators infiniteloop initialization interest kernel km linked linkedlist linux linuxsegmentationfault list lists locate logical_drives match matrix microsoft motherboard multi mysql number open opendocumentformat opensource owf pattern pdf performance pointer pointers posix power problem probleminc program programming pyramidusingturboccodes radix read recursion recv repetition research scanf scheduling scripting segmentationfault send sequential shape socketprograming stack standard string strings structures systemcall testautomation turboc unix user variable voidmain() wab win32api windows.h






