-1

I'm new to c and not really familiar with pointers or how this method is setup to be called in main with these arguments. I have a bit of an understanding of pointer snow, but i'm still confused with one being in the method arguments. Do I pass in a pointer and an int? Do I need to pass in anything at all? Do I even need the main method or can I just run the program with is_little_endian as my main method?

#include "test_endian.h"
#include <stdio.h>

int is_little_endian(void (*store)(int*,int)) {
  int x;

  unsigned char *byte_ptr = (unsigned char*)(&x);

  store(&x, 1);

  printf("the address for x is %u\n", *byte_ptr);

  return 0;
}


int main() {

}
Arcade
  • 1
  • 1

1 Answers1

0

Function is_little_endian accepts only one parameter which is neseccary.

This parameter is a pointer to a function, which accepts pointer to int, then int and returns nothing (void). You just need to pass there a pointer to some function, like that:

void example(int * a, int b) { }

int main() {
  is_little_endian(example);
}

Or any other function you wish. You can read more about pointers to function there: How do function pointers in C work?

And yes, you need the main method to run the program, like your body needs your heart. ;)

arorias
  • 318
  • 3
  • 14