Skip to main content
added 46 characters in body
Source Link
JoshD
  • 12.9k
  • 3
  • 46
  • 54

char *temp = "string"; will create a pointer temp that points to a string litteral. This string literal is stored in the data segment of the executable code. It is immutable and the address is still valid after the function returns.

char temp[] = "string"; will allocate 7 characters on the stack and set them equal to 'string'. These are mutable characters. In your example, theythe returned value points to characters that are destroyedno longer valid when they function returns.

char *temp = "string"; will create a pointer temp that points to a string litteral. This string literal is stored in the data segment of the executable code. It is immutable and the address is still valid after the function returns.

char temp[] = "string"; will allocate 7 characters on the stack and set them equal to 'string'. These are mutable characters. In your example, they are destroyed when they function returns.

char *temp = "string"; will create a pointer temp that points to a string litteral. This string literal is stored in the data segment of the executable code. It is immutable and the address is still valid after the function returns.

char temp[] = "string"; will allocate 7 characters on the stack and set them equal to 'string'. These are mutable characters. In your example, the returned value points to characters that are no longer valid when they function returns.

Source Link
JoshD
  • 12.9k
  • 3
  • 46
  • 54

char *temp = "string"; will create a pointer temp that points to a string litteral. This string literal is stored in the data segment of the executable code. It is immutable and the address is still valid after the function returns.

char temp[] = "string"; will allocate 7 characters on the stack and set them equal to 'string'. These are mutable characters. In your example, they are destroyed when they function returns.