0

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;

 for(ctr1=0;ctr1<10;ctr1++)
 {
  printf("Enter Name %d ", ctr);
  scanf("%s",stuname[ctr]);
 }

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

 for(ctr2=0;ctr2<10;ctr2++)
 {
  printf("%s\n", stuname[ctr2]);
 }

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

3
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by Adak
0

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

-1

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.
0

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.