Hello frnds. I want to knw tht how can we send an array by value in c.
abrarsyed 0 Newbie Poster
Recommended Answers
Jump to Post— deceptikon 1,790The short answer is you can't. The long answer is you can if you aren't pedantic about it.
An array can be copied by value by wrapping the array in a structure and then passing an instance of that structure. When the structure instance is copied, the array goes with …
Jump to Post— Sokurenko 42Another possible solution
#include <stdio.h> #include <stdlib.h> #include <string.h> void vPassByValue(const void * const vData, int iSizeOfData) { void *vCopyData = NULL; vCopyData = malloc(iSizeOfData); if(vCopyData != NULL) { memcpy(vCopyData, vData, iSizeOfData); printf("passed by value %s\n",vCopyData); memset(vCopyData, 0, iSizeOfData); } free(vCopyData); return; } int main() { char …
Jump to Post— DeanMSands3 69: I'm not the kind of guy who down-votes posts willy-nilly (unless you're being condescending and a complete ass), but your post is... not what the OP is asking for. Pass by value, not reference. Yours is reference. …
Jump to Post— deceptikon 1,790@Deceptikon: Back in the days of Turbo C, I remember folks saying never put an array in the arguments, and instead use its pointer AND the same thing about struct's.
While it's true for struct instances, arrays have always been passed "by pointer", even in the prehistory of …
All 15 Replies
deceptikon 1,790 Code Sniper Team Colleague Featured Poster
Sokurenko 42 Junior Poster
Sokurenko 42 Junior Poster
DeanMSands3 69 Junior Poster
deceptikon 1,790 Code Sniper Team Colleague Featured Poster
Sokurenko 42 Junior Poster
deceptikon 1,790 Code Sniper Team Colleague Featured Poster
DeanMSands3 69 Junior Poster
abrarsyed 0 Newbie Poster
abrarsyed 0 Newbie Poster
abrarsyed 0 Newbie Poster
Trentacle 112 Junior Poster in Training
Sokurenko 42 Junior Poster
abrarsyed 0 Newbie Poster
Trentacle 112 Junior Poster in Training
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.