#include <signal.h>
#include <stdio.h>
#include <stdlib.h>

void handler_divideByZero(int signum);

int main(void) {
  int result = 0;
  int v1 = 0, v2 = 0;
  void (*sigHandlerReturn)(int);

  sigHandlerReturn = signal(SIGFPE, handler_divideByZero);

  if (sigHandlerReturn == SIG_ERR) {
    perror("Signal Error: ");
    return 1;
  }

  v1 = 121;
  v2 = 0;
  result = v1 / v2;
  printf("Result of Divide by Zero is %d\n", result);
  return 0;
}

void handler_divideByZero(int signum){
  if(signum == SIGFPE){
    printf("Received SIGFPE, Divide by Zero Exception\n");
    exit(0);
  } else {
    printf("Received %d Signal\n", signum);
    return;
  }
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: