I am new to c programming and am working on a code that uses pointers.
#include <stdio.h>
int main(void) {
int x, y;
int *p_int; /* Pointer to an int */
x = 4;
y = 0;
p_int = &x; /* Pointer has address of x ("points to x") */
printf("x=%d, y=%d, *p_int=%d, p_int=%X\n", x, y, *p_int, p_int);
y = *p_int; /* Y now contains 4 also */
p_int = &y; /* Pointer now has address of y ("points to y") */
printf("x=%d, y=%d, *p_int=%d, p_int=%X\n", x, y, *p_int, p_int);
*p_int = *p_int * 2; /* Multiply what p points to by 2 */
printf("x=%d, y=%d, *p_int=%d, p_int=%X\n", x, y, *p_int, p_int);
return(0);
}
When I try to build it I am coming up with errors. I'm not sure where the errors are though. Can anyone help?
Well, it always helps if you tell us which error you get that you don't understand... ;)
In this case, the error is pretty obvious/self explanatory, just break the printf() statement down into printing each value separately and it will become apparent... 8)
Ralf
Quote from: Bitbeisser on December 01, 2013, 01:42:06 AM
Well, it always helps if you tell us which error you get that you don't understand... ;)
In this case, the error is pretty obvious/self explanatory, just break the printf() statement down into printing each value separately and it will become apparent... 8)
Ralf
Thank you for posting this. I was having the same problems.