Wrote the following code fragment and then I was set upon by

Wrote the following code fragment and then I was set upon by a ferocious boogie 1 of bloodthirsty weasels. What did I do to deserve this? What\'s the problem with gets? What should I have done instead? char str[16]; gets (\"%s\"); What is the difference between a function that passes its arguments by value and one that passes its arguments by reference? When might you need a function that uses pass-by-reference arguments?

Solution

6)

char str[16];

gets(\"%s\");

Here when we are using gets we no need to use % to read the value entered by the user.The reading with \"gets\" is simple when compared with scanf().here simply we can write gets(str); to read the string entered by the user.This will read the string until the newline character encounters.

gets(str);

_________________________________

7)

If we pass the values as arguments to the function while calling then that function this is called pass - by value.

If we are passing the address of that variables as arguments while calling the function ,it is called as pass by reference.

During pass by value the function uses those arguments and performed required calculations .But in the main method the variables values will not get changed .remains same.

But if we use pass by reference if we performs any operations on those values which was refered by the reference.Then that changes will get effected.when we want the changed values after performing the operations on the values then we have to use pass by reference.

____________________________________

 Wrote the following code fragment and then I was set upon by a ferocious boogie 1 of bloodthirsty weasels. What did I do to deserve this? What\'s the problem w

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site