Re: Question on arrays within a struct and sprintf





aap wrote:
> I have the following code
> #define MAX 32
> struct A
> {
> char carr[MAX];
> int iarr[MAX];
> int i;
> };
> void main()
> {
> struct A a;
> strcpy(a.carr, "a.carr Test1");
> char test[MAX];
> strcpy(test, "2Test2");
> sprintf(test, "%s", &a.carr); //method1
> printf("%s\n", test);
> sprintf(test, "%s", a.carr); //method2
> printf("%s\n", test);
> }
> I use sprintf twice. In the first case I pass &a.carr as the argument
> and in the second caseI pass a.carr as the argument.
> In both the cases, the code works just fine.
> Why does it not fail in the first case?
> How come &a.carr and a.carr both produce identical results?
>
> I apologize if this is already covered in a faq.

It's sort of covered by Questions 6.12 and 6.12 in
the comp.lang.c FAQ list

http://www.eskimo.com/~scs/C-faq/top.html

Check them out, and ask again if it's still not clear.
(While you're at it, see Question 11.2 as well.)

--
Eric.Sosman@xxxxxxx

.



Relevant Pages