V
vlsidesign
I am a newbie to C, and was hoping to get a little bit better handle
on this until I get deeper into pointers, etc. I kind of understand it
some, but still unfamiliar because I haven't got to pointers and using
them yet. Here is my program:
#include <stdio.h>
int main()
{
char yourname[10];
int yourworth;
printf("what's your name? ");
scanf(" %s", yourname);
printf("how many millions of dollars are you worth? ");
scanf(" %d", &yourworth);
printf("\n %s is worth %d \n", yourname, yourworth);
return 0;
}
I think that the scanf needs the second argument to be a pointer? I
believe that the value of a pointer is an memory address (which the &
ampersand address operator) retrieves? So when I put an ampersand in
front of the variable name "yourworth" that it returns the address,
which then the scanf then puts the value scanned into that memory
location? In the case of a string, which is just an array of
characters, like "yourname" above, it is really a pointer anyway, and
it's value is already an address, so the ampersand is not needed
anyway??
on this until I get deeper into pointers, etc. I kind of understand it
some, but still unfamiliar because I haven't got to pointers and using
them yet. Here is my program:
#include <stdio.h>
int main()
{
char yourname[10];
int yourworth;
printf("what's your name? ");
scanf(" %s", yourname);
printf("how many millions of dollars are you worth? ");
scanf(" %d", &yourworth);
printf("\n %s is worth %d \n", yourname, yourworth);
return 0;
}
I think that the scanf needs the second argument to be a pointer? I
believe that the value of a pointer is an memory address (which the &
ampersand address operator) retrieves? So when I put an ampersand in
front of the variable name "yourworth" that it returns the address,
which then the scanf then puts the value scanned into that memory
location? In the case of a string, which is just an array of
characters, like "yourname" above, it is really a pointer anyway, and
it's value is already an address, so the ampersand is not needed
anyway??