c++ - does a function know how much memory its parameters occupy? -
when call function passing value, making copy in memory of actual parameters' value.
the question is: function know how space parameters occupy in memory? if answers yes, how can retrieve in function scope?
if answers in no, have potentially hidden memory error?
consider example:
#include <stdio.h> void func(char * x) { x +=98; *x='c'; //is ok? or have hidden memory error? *++x='\0'; --x; puts(x); } int main() { char a[100]; char *b =a; func(b); return 0; }
you have potentially hidden error. don't manually crap use std::string
.
Comments
Post a Comment