0

I writing a function that will print out hexadecimal inside unsigned char array. But I can't get the size of the array. I tried using sizeof() but it seems to print out the size of the type which is 4.

if(raw_instr[0]==0x68){
    printf("%d\n",sizeof(raw_instr));
    for(int i=0; i<sizeof(raw_instr);i++){
        printf("%x ",raw_instr[i]);//expect to print 68 10 3f 0 0 but it print only 68 10 3f 0
    }
    printf("\n");
}

This is the array that I will take in for loop.

unsigned char inst1[5] = {0x68,0x10,0x3f,0x00,0x00};
Nattapat
  • 19
  • 4
  • 1
    UnholySheep might be right. But wiht the lack of [mre] I suspect it is more https://stackoverflow.com/questions/17590226/finding-length-of-array-inside-a-function – Yunnosch Nov 27 '21 at 14:42
  • I trying to get the length of the unsigned char array. like in inst1 I expect it to be 5 because it have 5 element in them. However, when I try using sizeof(raw_instr), the output is 4 which I think it size of the type not the size of the array. and I also tried sizeof(raw_instr[0]) the output is 1. So sizeof(arr)/sizeof(arr[0]); doesn't work as expected. – Nattapat Nov 27 '21 at 15:07

0 Answers0