so im working on a mid-term exam average program of a class of 10 students. would my code start as follows?

void getnames(char stuname[10][20])
 int ctr;

  printf("Enter Name %d ", ctr);

void printnames(char stuname[10][20])
 int ctr2;

  printf("%s\n", stuname[ctr2]);

and have getNAME as a global function?
Hope my question makes sense. Im still in the pseudocode phase

8 Years
Discussion Span
Last Post by Adak

While you're getting their name, don't you also want to get their exam score?

Are you going to use parallel arrays student name <==> their score sharing the same index, or what's your plan for that?

I like all the major functions to be up above main(). Easy to refer to, and all together. Only very minor one's are put inside the calling function.

Edited by Adak: n/a


You are passing the arrays by value. The changes made to these arrays will be local to the function.
Pass by pointer or use global variables

Votes + Comments
Arrays can't be passed by value the way you imply.

Arrays are *always* passed by reference. (More accurately, the array is "degraded" (becomes just a pointer), which is then passed by copying, but since a pointer is just an address anyway, it's a pass by reference, via proxy.

That's how C always does pass by reference, btw. When we send a pointer to a function, the pointer that arrives is just a copy of the pointer that was listed in the call. The effect is the same as if the original pointer was sent, so no trouble.

Edited by Adak: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.