I'm coming from C# and I'm learning C++ (with this tutorial) so I have a relatively insubstantial amount of knowledge on memory, but the only use I see in pointers is "saving space" and iterating through arrays. So why do functions like the scanf function take pointers as parameters? For instance:
printf("What's your name?: ");
and then:
scanf("%s",&userName). Wouldn't it make more sense to just pass the variable itself as an argument? The C book I was looking at said that using the variable itself would produce unexpected results, but I don't see why. Could anyone please enlighten me in a C++ fashion? I switched from learning C because I realized how much I love OOP.
iostreamwhich is c++ there won't be pointers, only references. Trycin >> userName;scanfis C++. Most of the C standard library is included in C++ by reference.scanfis C andstd::scanfis C++. Also, @airplaneman19, please show the declaration ofuserName: is it likechar* userName;orchar userName[MAX_LEN];?