引发了异常: 读取访问权限冲突。 **p** 是 nullptr。警告 C6011:取消引用 NULL 指针 < 名称>
#include <malloc.h> void f( ) { char *p = ( char * ) malloc( 10 ); *p = '\0'; // code ... free( p ); }
修改
#include <malloc.h> void f( ) { char *p = ( char * )malloc ( 10 );
//若要更正此警告,请检查指针中是否具有 null 值 if ( p ) { *p = '\0'; // code ... free( p ); } }
若要更正此警告,请检查指针中是否具有 null 值,如以下代码所示:
#pragma once #include<stdio.h> #include<stdlib.h> typedef struct Node { int data; struct Node* pnext; }Node,*Link;
#include"func.h" Node* enter(Node* stack, int i) { Node* node; node = (Link)malloc(sizeof(Node)); if (node) { node->data = i; node->pnext = stack; } return node; } Node* pop(Node *stack) { Node* p; p = stack; if (!p) printf("EmptyStack");
//若要更正此警告,请检查指针中是否具有 null 值 if (p) { printf("%2d\n",p->data); stack = p->pnext; free(p); return stack; } } main() { Node* stack; stack = NULL; stack = enter(stack, 0); stack = enter(stack, 1); stack = enter(stack, 2); stack = enter(stack, 3); stack = enter(stack, 4); stack = pop(stack); stack = pop(stack); stack = pop(stack); stack = pop(stack); stack = pop(stack); stack = pop(stack); system("pause"); }