#include <stdio.h>
#include <string.h>
int * bin(char a);
int main(void){
char a='a';
int k=0;
int *binary;
binary=bin(a);
for(k=0; k<8; k++){
printf("%d", *binary++);
printf("\n");
}
return 0;
}
int *bin(char a){
int i=0;
int *arr;
int output[8];
char c=a;
for (i = 0; i <8 ; ++i) {
output[8-i-1] = (a >> i) & 1;
}
arr=&output[0];
// for (i = 0; i <8 ; ++i) {
// printf("%d", output[i]);
// }
// printf("\n");
return arr;
}
The ouptut should be the binary value of the char 'a'which is: 0 1 1 0 0 0 0 1
but i got this instead: 0 -1216804320 -1218095335 -1216804320 10 -1076423592 -1218208721 -1216804320
Is this a pointer problem? How do i fix it so it would print the right answer? thx!!