+ 1
Whats the output and why ?
#include<stdio.h> main() { int x = 65, *p = &x; void *q=p; char *r=q; printf("%c",*r); }
3 Respostas
+ 2
The output should be 'A' because 65 is the code point for 'A' in ASCII and UTF-8.
+ 2
I must differ with Varshini. A compiler will accept this code and execute it as I predicted. C (unlike more strongly typed languages) is permisive in the assignment of pointers and will perform type conversions automatically. This is particularly true of void pointers which are essentially typeless memory addresses.
I should further qualify my earlier answer. I assumed a little-endian byte ordering (which is true for Intel based systems and many others). In the less common big-endian byte order, the pointer would point to a byte containing zero (0) which is a null character in most character encodings.
+ 1
A pointer is a variable that is used to store the address of another variable.The data type of pointer variable and the address of variable to be stored must be same.In your case,you have declared different data types(int,void,char).The complier wont execute it.If you assign all pointer variables in integer,the output will be A. Since the ASCII value of 65 is A,it will display A.