Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   diffrence between a char pointer and char pointer inside a class(private) (http://www.go4expert.com/forums/diffrence-char-pointer-char-pointer-t23456/)

rafeek610 1Oct2010 15:21

diffrence between a char pointer and char pointer inside a class(private)
 
what is the diffrence between a char pointer and char pointer inside a class(private)

jimblumberg 2Oct2010 02:31

Re: diffrence between a char pointer and char pointer inside a class(private)
 
The char pointer in the class can only be accessed by class members.

rafeek610 3Oct2010 13:11

Re: diffrence between a char pointer and char pointer inside a class(private)
 
i asked about not that diffrence...............
in normal char pointer we can have to allocate contineous memory for storing string(implicitly)..........
is it possible in the case of a class member..........................
eg:
char *str;
scanf("%s",str);
will store the strring inside str(without allocating memory explicitly(means not using malloc))............
but is it possibe for a class private member..............
plz mension an eg!!!!!!!!!!!!

jimblumberg 3Oct2010 19:00

Re: diffrence between a char pointer and char pointer inside a class(private)
 
You must explicitly allocate memory for a string in any scope in c/c++. You must first allocate memory for a pointer before using. Your example will produce undefined results. Some times it may seem to work, but it is writing to memory it does not own.

Jim

rafeek610 4Oct2010 13:30

Re: diffrence between a char pointer and char pointer inside a class(private)
 
but in the case char pointer its always true in normal case...........
what happent in the case of class variable

jimblumberg 4Oct2010 20:29

Re: diffrence between a char pointer and char pointer inside a class(private)
 
You must explicitly allocate memory for a cstring in any scope in c/c++. I does not matter if it is in a class/structure, global, or local pointer.


All times are GMT +5.5. The time now is 16:35.