0

When I am debugging and watching the value of the variable at input_array(),the value inputted seems to be saved. However when it comes to the main function, somehow all the inputs in the struct are gone.

#include <stdio.h>
#define MAXN 100

struct sortedArray{
  int data[MAXN];
  int count;
};

void input_array(struct sortedArray a){
  scanf("%d",  &a.count);
  for (int i = 0; i < a.count; i++){
    scanf("%d", &a.data[i]);
  }
}

int main(){
  struct sortedArray a;   
  input_array(a);
        
  for (int i = 0; i < a.count; i++){
    printf("%d ", a.data[i]);
  }    
  return 0;
}
  • Also could be considered a duplicate of https://stackoverflow.com/questions/373419/whats-the-difference-between-passing-by-reference-vs-passing-by-value. But basically this question is: "What's the difference between pass-by-value and pass-by-pointer?" – Bill Lynch Feb 24 '22 at 16:54

0 Answers0