Could you post the results of running this code.
#include <stdio.h>
int main()
{
int x;
fprintf(stdout, "size->%lu\n", sizeof(void*));
fprintf(stdout, "size->%lu\n", sizeof(int));
fprintf(stdout, "size->%p\n", (void*)&x);
fprintf(stdout, "size->%d\n", (int)&x);
return 0;
}
gerard4143
Nearly a Posting Maven
2,295 posts since Jan 2008
Reputation Points: 512
Solved Threads: 397
Skill Endorsements: 0
Sure:
size->4
size->4
size->0022FF4C
size->2293580
~G
I just wanted to make sure you weren't truncating anything..
Now lets look at
int * p3 = "47352";//assign to pointer p3, the pointer that points to "47352"
Unknown (with asterisk): 892548916
*p3 produces 892548916
now 892548916 has a hex value of 0x35333734 which has ascii values
0x35 = '5'
0x33 = '3'
0x37 = '7'
0x34 = '4'
notice that p3 points to "47352" which is an int pointer and int are four bytes on your system so your getting the first four characters of the string "47352".
gerard4143
Nearly a Posting Maven
2,295 posts since Jan 2008
Reputation Points: 512
Solved Threads: 397
Skill Endorsements: 0
I would say that this is the value of the address held by p3
Unknown (without asterisk): 4210883
gerard4143
Nearly a Posting Maven
2,295 posts since Jan 2008
Reputation Points: 512
Solved Threads: 397
Skill Endorsements: 0
And the last one
char * p2 = "Some string";
printf("Unknown (with asterisk): %d\n", *p2);
Unknown (with asterisk): 83
dereferncing a character pointer returns the character pointed to which is 'S' and the numeric(ascii) value of 'S' is 83.
gerard4143
Nearly a Posting Maven
2,295 posts since Jan 2008
Reputation Points: 512
Solved Threads: 397
Skill Endorsements: 0
Question Answered as of 1 Year Ago by
gerard4143