Using characters & strings, we normally write char{a,b,c,d} and string(a,b,c,d), what is the main difference between them, can we use them interchanging their positions?

  • Possible duplicate of: cs50.stackexchange.com/questions/2298/pointer-concepts/…
    – kzidane
    Aug 16 '14 at 11:00
  • 1
    @PRADEEP "we normally write char{a,b,c,d} and string(a,b,c,d)..." Neither of these looks like very common syntax, what is this statement based on? Could you provide a reference or an example of where you have seen or used this? Aug 16 '14 at 11:44

string is a variable type defined by the CS50 library - it does not normally exist in C. Looking at the code for CS50.h will show this:

 * Our own data type for string variables.

typedef char *string;

This line could be read that a new type is defined, as a char *, called string. In other words, string is defined as exactly the same thing as a char *. They are identical and can be used interchangeably, so wherever you write char *, you can also write string.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .