malloc申请空间失败
程序代码:
#include <stdio.h> #include <malloc.h> void swap(int* x, int* y) { int t; t = *x; *x = *y; *y = t; } void rank(int* nums, int size) { for (int i = 0; i < size; i++) for (int n = 0; n < size - i; n++) if (nums[i] > nums[i + 1]) swap(&nums[i], &nums[i + 1]); } int main() { printf("请先输入您要输入的数组长度\n"); int size; scanf_s("%d", &size); int* p = (int*)malloc(size * sizeof(int)); printf("请输入您要输入的一组数\n"); for (int i = 0; i < size; i++) { scanf_s("%d", p); p++; } rank(p, size); for (int i = 0; i < size; i++) { printf("%d ", *p); p++; } return 0; }