Sunday, July 12, 2009

We dont use & in scanf function in c for reading strings .y is it so?

Bcoz, the char itself returns the address...


so no need for using '%26amp;' before it...

We dont use %26amp; in scanf function in c for reading strings .y is it so?
yeah! we don't use scanf ,instead we use 'gets' %26amp; for printing a string we use 'puts'. this is b'coz scanf won't take spaces in between words,but using gets would avoid this problem.
Reply:Yes buddy,





take the below eg.





int number;


char name[10];





when ever you specify the name of a integer variable, i.e number, you are indicating just the content of the variable. If you get a input for that variable, you have to store that input in the memory location. so when put %26amp; before the variable name, ie. %26amp;number, now you are indicating the memory location of that integer, where you are going to store the input.





But in the case of string, whenever you specify the name of the variable, you are directly indicating the base address of that string. i,e by giving just name with out %26amp;, you specify the start address of the memory location from where you have store the input.





. . .

garland flower

No comments:

Post a Comment