A solution for n-queens in C
//if I don't write this loop, the 0s get printed as 3452816845....Why???



Because malloc doesn't initialize an allocated memory. It contains garbage. You may avoid the explicit loop by using calloc.

As a side note, prefer sizeof(variable) to sizeof(type), e.g.

board[i] = malloc(sizeof(*board[i]) * sizeOfBoard);


This way, if you ever change the type of board squares, this line wouldn't change. No double maintenance.
The code adds queens into the rows sequentially. There is no need to test lower diagonals: there are no queens there yet.
Working with the entire 2-dimensional board is an overkill. A one-dimensional array of queen files suffices. Besides, testing for placement safety becomes much simpler:

bool is_safe(int * queens, long long row, long long col, long long dim) {
    for (long long rank = 0; rank &lt; row; rank++) {
        if (queens[rank] == col) {
            // Another queen is at this column already
            return false;
        if ((row - rank) == abs(queens[rank] - col)) {
            // A square is under diagonal attack
            return false;
        }
    return true;
}

A for having all the solutions, do not break the loop when retVal == 1, and

if (row_index == boardSize) {
    do_something();
    return 1;
}


where do_something() may print the board, or save the board in a global state, or whatever suites your needs.