1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

diffrence between a char pointer and char pointer inside a class(private)

Discussion in 'C' started by rafeek610, Oct 1, 2010.

  1. rafeek610

    rafeek610 New Member

    Joined:
    Sep 24, 2010
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    0
    what is the diffrence between a char pointer and char pointer inside a class(private)
     
  2. jimblumberg

    jimblumberg New Member

    Joined:
    May 30, 2010
    Messages:
    120
    Likes Received:
    29
    Trophy Points:
    0
    The char pointer in the class can only be accessed by class members.
     
  3. rafeek610

    rafeek610 New Member

    Joined:
    Sep 24, 2010
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    0
    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!!!!!!!!!!!!
     
  4. jimblumberg

    jimblumberg New Member

    Joined:
    May 30, 2010
    Messages:
    120
    Likes Received:
    29
    Trophy Points:
    0
    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
     
    shabbir likes this.
  5. rafeek610

    rafeek610 New Member

    Joined:
    Sep 24, 2010
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    0
    but in the case char pointer its always true in normal case...........
    what happent in the case of class variable
     
  6. jimblumberg

    jimblumberg New Member

    Joined:
    May 30, 2010
    Messages:
    120
    Likes Received:
    29
    Trophy Points:
    0
    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.
     
    shabbir likes this.

Share This Page