gpt4 book ai didi

c - 错误: indirection requires pointer operand ('int' invalid)

转载 作者:行者123 更新时间:2023-11-30 20:04:40 62 4
gpt4 key购买 nike

这段代码的目的是传递一个十进制的虚拟地址并输出页码和偏移量。

在 Linux 上使用 gcc 编译器编译代码后,出现以下错误:

indirection requires pointer operand ('int' invalid) virtualAddress = *atoi(argv[1]);

#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <unistd.h>
#include <math.h>
#include <curses.h>

int main(int argc,char *argv[])

{

unsigned long int virtualAddress,pageNumber,offset;

if(argc<2){

printf(" NO ARGUMNET IS PASSED");

return 0;

}

virtualAddress = *atoi(argv[1]);

//PRINT THE VIRTUAL ADDRESS

printf("The Address %lu contains:",virtualAddress);

//CALCULATE THE PAGENUMBER

pageNumber = virtualAddress/4096;

//PRINT THE PAGE NUMBER

printf("\n Page Number = %lu",pageNumber);

//FIND THE OFFSET

offset = virtualAddress%4096;

//PRINTS THE OFFSET

printf("\n Offset = %lu",offset);

getch();

return 0;

}

最佳答案

当您想通过 *my_var 而不是 &my_var 创建指向变量的指针时,会发生此错误。

关于c - 错误: indirection requires pointer operand ('int' invalid),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38237355/

62 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com