I’m having trouble compiling a simple C program

Asked

Viewed 97 times

0

# include <stdio.h>

int main(){
int y = 5;
int *yPtr;

printf("Address of y veriable: %x \n",&y);

printf("Address stored in yPtr variable: %x \n", yPtr);

printf("Value of y: %d\n", y);

printf("Value of *& yPtr : %x \n", *&yPtr);
printf("Value of &* yPtr : %x \n", &*yPtr);

return 0;
}

At compile time compiler shows the following message:

(format ‘%x’ expects argument of type ‘unsigned int’, but argument 2 has type ‘int *’ [-Wformat=]
 printf("Value of &* yPtr : %x \n", &*yPtr);
                            ~^
                            %ls).

I wanted because the compiler shows this warning to use %ls.

  • 1

    But what you hoped would happen when you do printf("Value of &* yPtr : %x \n", &*yPtr); ? What was the result you had in mind ?

  • a hexadecimal result

  • 1

    and what would be the value ? and this value represents what ?

1 answer

1


No y, do not need the "&" in the printf, and put "%d" since it is of type int

# include <stdio.h>

int main(){
int y = 5;
int *yPtr;

printf("Address of y veriable: %d \n",y);

printf("Address stored in yPtr variable: %d \n", yPtr);

printf("Value of y: %d\n", y);

printf("Value of  yPtr : %d \n", &yPtr);
printf("Value of  yPtr : %d \n", &yPtr);

return 0;
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.