Q:

C program not printing

I have written the following program:
#include<stdio.h>
#include<math.h>
#include<stdlib.h>

void inttobusn(int val, int n, char* bus)
{
    int i;
    unsigned int digit;

    for (i=0; i < n; i++) {
            digit = pow(2, (n-1-i));
            if (digit <= val) {
                    val -= digit;
                    bus[i] = '1';
                    //printf("hello %c",bus[i]);
            } else {
                    bus[i] = '0';
            }       
     }
} 
main(){
  char* bus;
  inttobusn(37,8,bus);
  int i=0;
  //printf("%s",bus);
  for(i=0;i<12;i++){
      printf("%c",bus[i]);
  }
}

But on running it doesn't print the elements of the array bus. It doesn't print anything. I am unable to figure out what is wrong. Please could someone point out?

A:

Your code is buggy! you don't allocate memory for the bus[] array, and are trying to access values at garbage location as e.g bus[i] = 0; -- Undefined Behavior in C standard, Undefined means you can't predict how your code will behave at runtime. 
This code compiled because syntax-wise the code is correct but at runtime the OS will detect illegal memory access and can terminate your code. (interesting to note: as OS detects memory right violation by a process -- An invalid access to valid memory gives: SIGSEGV And access to an invalid address gives: SIGBUS). In the worst case your program may seem execute without any failure, producing garbage results.
To simply correct it define bus array as char bus[N]; else allocated memory dynamically using void* malloc (size_t size);
Additionally, suggestion to your from @Lochemage and @Ran Eldan: 
You need to declare bus with a specific size, like char bus[12]. It has to be at least large enough to fit 12 chars because your for loop at the end is iterating through that many (and you can check your code working with this suggestion @codepade).   
Also there is no return type to main() in your code, its should be int main(void).    

