Aite. I'll post a mesage on the compiler's support forum to get insights there. Thank you.
Printable View
Aite. I'll post a mesage on the compiler's support forum to get insights there. Thank you.
Actually, it is also pass by reference.Code:$cat t.c
#include <stdio.h>
void f(char r[])
{
r[4]='%';
puts(r);
return;
}
int main()
{
char a[]="dlkfsgjflkgsd";
f(a);
puts(a);
return 0;
}
$gcc t.c -Wall -Werror -ansi -pedantic
$./a.out
dlkf%gjflkgsd
dlkf%gjflkgsd
$
In C? Does references exist in C?
Yes, I meant that you can actually pass data that can be modified w/o using pointers.
But it appears you can... Basically char[] and char* is the same, only char* needs dereference.
Ah, nevermind. C just weirds me out.
But there's no difference there between C and C++ - of course, if you pass a struct or class (such as string), rather than an array, then you would pass a COPY of the struct or class, which is why a std::string passed in C++ doesn't modify the original string unless you specify either a & or * in the function parameter [and relevant & if needed in the calling code].
--
Mats
I've learned that type[] and type* is basically the same thing, can be treated as the same thing when it comes to modifying strings, at least.
I never pass by char[], I pass by char* if such is needed, that's why it weirded me out.
I also remember that I was told that passing char[] is also by reference for arrays in my first college course on C.
Well, I suppose either is fine.
I have gotten a reply from mikroelectronika forums with a project that manages to compile properly (although I haven't tried it yet). Apparently it's a hardware problem. Passing char array as char* which is allocated in the RAM of the microcontroller through a parameter const char* which is allocated in the ROM is an illegal action in the hardware configuration.