I have been trying to study C about 3 days, and have a question about pointer/address
this is my code
#include <stdio.h>
#define EOL '\n'
int main()
{
char one = 1;
char two = 2;
char three = 3;
char* onePointer = NULL;
char* twoPointer = NULL;
char* threePointer = NULL;
onePointer = &one;
twoPointer = &two;
threePointer = &three;
printf("%cOne variables: %d%c", EOL, one, EOL);
printf("Two variables: %d%c", two, EOL);
printf("Three variables: %d%c", three, EOL);
printf("%cOne adress: 0x%X%c", EOL, onePointer, EOL);
printf("Two adress: 0x%X%c", twoPointer, EOL);
printf("Three adress: 0x%X%c", threePointer, EOL);
return 0;
}
when I try to compile it I get the following error "warning: format specifies type 'unsigned int' but the argument has type 'char *' [-Wformat]enter code here printf("%cOne adress: 0x%X%c", EOL, onePointer, EOL);" the same code does work on WINDOWS 7. (I have been watching youtube courses where the guy writes this code on win7)
If I changed %X
to %p
it compiles successfully "
One variables: 1
Two variables: 2
Three variables: 3
One adress: 0x0x7fff52381c0b
Two adress: 0x0x7fff52381c0a
Three adress: 0x0x7fff52381c09"
but if i run the output file again, every time i have different address it is ok?
One variables: 1
Two variables: 2
Three variables: 3
One adress: 0x0x7fff55b56c0b
Two adress: 0x0x7fff55b56c0a
Three adress: 0x0x7fff55b56c09
Oh, and one other question, I started my studies on WIN, then continued on mac os because looking in iOS dev side. So in windows I can create a function
char main()
void main(void)
whereas in Mac OS if recreate this example I get the error: " warning: return type of 'main' is not 'int' [-Wmain-return-type]" WHY?