Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Search results

  1. entrocraft

    Why is my variable returning a large negative number when dividing?

    Here are a few issues with your code where that negative number could be the result of undefined behavior. get_long isn't defined and number isn't initialized to a number less than zero. Some of the int declarations are too small while others can be smaller based on their maximum possible...
  2. entrocraft

    C Does type before malloc even matter ?

    I suggest using long instead of int to avoid truncation as well. #include <stdio.h> #include <stdlib.h> int main() { long *matrix = malloc(sizeof(long)); if (matrix != NULL) { *matrix = 2562323; } else { exit(EXIT_FAILURE); } printf("%ld", *matrix); return...
  3. entrocraft

    C Does type before malloc even matter ?

    It's undefined behavior to assign an object to uninitialized memory. int has a defined 2 or 4 byte width, so maybe the compiler is using sizeof(int) from the data type of the declared matrix pointer. A program compiled using this code could arbitrarily fail or produce different outputs. The...
Back
Top Bottom