Hi gunjan,

Can you please tell me what is the difference between void function(int*d); and void function(int &d); both above are function declarations and both we do the changes to the original variable passed to the function. Then what is the exact difference.

Thanks in advance

H...!

Can you please tell me out of fgets() and gets() which function is safe to use and why? If possible give an example program for explanation.

fgets is always safe... cause in fgets we can specify the size of the string that should be read... in such a case we can be sure only the specified no of bytes will be read...

gets is not like that... it will read whatever we give and may overwrite the memory locations not allocated for that particular string variable...


eg:

char acName[20];

/* Using fgets */
fgets(acName, 20, stdin);

/* Using gets */
gets(acName);

For the first one using fgets, even if we give any string greater than 20 in length, it will accept only 20.... but in gets if we give string of length 30, it will accept all the 30 and over write the memory locations not allocated for acName...


Hope it clears your doubt...

Hi gunjan,

Can you please tell me what is the difference between void function(int*d); and void function(int &d); both above are function declarations and both we do the changes to the original variable passed to the function. Then what is the exact difference.

Thanks in advance

The first one is "passing arguments to pointers". In that way, you can change original variable!
Second one is "passing arguments as references".
You cannot do that in C, C always passes arguments by value (yes, even if you use pointers, but then it passes pointer as value, not original value pointed by pointer :) )

So, the first one is ok in C and C++
Second one is only C++

Comments
Nicely put. :)

im having lot of problems in c and c++ programs...can u please tell me the sites where i ciuld find the solutions of almost all c/c++ programs..

im having lot of problems in c and c++ programs...can u please tell me the sites where i ciuld find the solutions of almost all c/c++ programs..

Solutions to ALMOST ALL C/C++ programs? That's asking for quite a lot, dontcha think? We don't even have ALMOST ALL C/C++ problems yet. :icon_rolleyes:

This article has been dead for over six months. Start a new discussion instead.