Thread: differentiate string

  1. #1
    Registered User
    Join Date
    Sep 2010
    Posts
    32

    Lightbulb differentiate string

    char *str = "hello";
    char str[] = "hello";

    can u differentiate these?

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    Sure I can:
    Code:
    #include <stdio.h>
    
    int main(void)
    {
      char *str = "hello";
      char str2[] = "hello";
    
      printf("%d - %d\n", sizeof(str), sizeof(str2));
    
      return 0;
    }
    Output:
    Code:
    4 - 6
    If you understand what you're doing, you're not learning anything.

  3. #3
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,059
    Quote Originally Posted by itsme86 View Post
    Output:
    Code:
    4 - 6
    lol!

  4. #4
    Registered User
    Join Date
    Mar 2009
    Posts
    344
    That's a difference, not a differentiation. To differentiate you'd have to do d(str1)/dx * dx/d(str2).

    To the op. One's a pointer which holds the address of a memory location holding "hello\0" - this memory location is likely read-only if you're using a modern compiler. The other's a read/write array holding "hello\0". See C Strings (Arrays vs. Pointers)

  5. #5
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    Quote Originally Posted by KCfromNC View Post
    That's a difference, not a differentiation. To differentiate you'd have to do d(str1)/dx * dx/d(str2).
    Really, dufus?

    According to Meriam Webster, one of the definitions for differentiate is: "to mark or show a difference in : constitute a difference that distinguishes".

    I'd say that's exactly what I did.
    If you understand what you're doing, you're not learning anything.

  6. #6
    Registered User
    Join Date
    Mar 2009
    Posts
    344
    Quote Originally Posted by itsme86 View Post
    Really, dufus?

    According to Meriam Webster, one of the definitions for differentiate is: "to mark or show a difference in : constitute a difference that distinguishes".

    I'd say that's exactly what I did.
    Jezz, it's a math joke answered by another one. Lighten up a bit.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. OOP Question DB Access Wrapper Classes
    By digioz in forum C# Programming
    Replies: 2
    Last Post: 09-07-2008, 04:30 PM
  2. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 11:03 PM
  3. Something is wrong with this menu...
    By DarkViper in forum Windows Programming
    Replies: 2
    Last Post: 12-14-2002, 11:06 PM
  4. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 03:23 PM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM