Can I return an array from a function?
hket89 0 Light Poster
Recommended Answers
Jump to PostReturning an array as a whole is not possible in c-language. However you may use one of the following method:
1. Store an array within a structure and then return the structure.
2. Dynamically allocate space for the array and then return the pointer
to that allocated space.
Jump to Postyou can also make a global variable and edit its contents in your function, so you wont be in need of returning anything
to dynamically allocate you can:#include <stdio.h> char *function (void) { char *myArray = "Hello World!\n"; return myArray; } int main (void) …
All 6 Replies
kvprajapati 1,826 Posting Genius Team Colleague
tux4life commented: Always to the point :) +22
hket89 0 Light Poster
Alibeg 1 Junior Poster in Training
hket89 0 Light Poster
Alibeg 1 Junior Poster in Training
wheel 72 Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.