Skip to main content
added 51 characters in body
Source Link
kzidane
  • 17.7k
  • 3
  • 28
  • 100

Or

char str[4];
strcpy(str, "foo");

Syntactic sugar makes the language sweeter by providing easier and quicker ways to do more complicated things.

NOTICE though that you'd be able to modify the contents of the string in the second and, the third, and the forth examples because these wouldn't be constant strings as it's the case with the string literal example. To be honest, there are situations where you have to create a string probably in one of the other two thesethree ways to be able to modify the string's contents.

Syntactic sugar makes the language sweeter by providing easier and quicker ways to do more complicated things.

NOTICE though that you'd be able to modify the contents of the string in the second and third examples because these wouldn't be constant strings as it's the case with the string literal example. To be honest, there are situations where you have to create a string probably in one of the other two these ways to be able to modify the string's contents.

Or

char str[4];
strcpy(str, "foo");

Syntactic sugar makes the language sweeter by providing easier and quicker ways to do more complicated things.

NOTICE though that you'd be able to modify the contents of the string in the second, the third, and the forth examples because these wouldn't be constant as it's the case with the string literal example. To be honest, there are situations where you have to create a string probably in one of the other three ways to be able to modify the string's contents.

added 1 character in body
Source Link
kzidane
  • 17.7k
  • 3
  • 28
  • 100

NOTICE though that you'd be able to modify the contents of the string in the second and third examples because these wouldn't be constant strings as it's the case with the string literal example. To be honest, there are situations where you have to create a string probably in one of the other two these ways to be able to modify the string's contents.

NOTICE though that you'd be able to modify the contents of the string in the second and third examples because these wouldn't be constant strings as the string literal. To be honest, there are situations where you have to create a string in one of these ways to be able to modify the string's contents.

NOTICE though that you'd be able to modify the contents of the string in the second and third examples because these wouldn't be constant strings as it's the case with the string literal example. To be honest, there are situations where you have to create a string probably in one of the other two these ways to be able to modify the string's contents.

added 1 character in body
Source Link
kzidane
  • 17.7k
  • 3
  • 28
  • 100

I don't think this is the question you should ask since you could simply hashave an answer to it by opening up a text editor, writing the code you want and then try to compile it see if it compiles or not.

Array names decay to pointers (i.e., if you used the name of an array butby itself, then you're using a pointer to the whole array which happens to be also a pointer to the first element in the array). So str here is mainly a pointer to the whole array, but it also could be a pointer to the first element in the array (i.e., the char 'f' in this case).

I don't think this is the question you should ask since you could simply has an answer to it by opening up a text editor, writing the code you want and then try to compile it see if it compiles or not.

Array names decay to pointers (i.e., if you used the name of an array but itself, then you're using a pointer to the whole array which happens to be also a pointer to the first element in the array). So str here is mainly a pointer to the whole array, but it also could be a pointer to the first element in the array (i.e., the char 'f' in this case).

I don't think this is the question you should ask since you could simply have an answer to it by opening up a text editor, writing the code you want and then try to compile it see if it compiles or not.

Array names decay to pointers (i.e., if you used the name of an array by itself, then you're using a pointer to the whole array which happens to be also a pointer to the first element in the array). So str here is mainly a pointer to the whole array, but it also could be a pointer to the first element in the array (i.e., the char 'f' in this case).

Source Link
kzidane
  • 17.7k
  • 3
  • 28
  • 100
Loading