1

why I can not assign it like this:

char c1 []="Odin";
   c1=c1+1;

Note that I include

#include<string.h>

8
  • Because you cannot assign to arrays. What do you want to do? Commented Apr 24, 2021 at 0:19
  • 1
    What should c1=c1+1; do? Do u want the string to go from "Odin" to "Pdin" ? Or to remove the letter O ? Commented Apr 24, 2021 at 0:22
  • @Tudor yes I want to remove the letter O Commented Apr 24, 2021 at 0:23
  • 1
    You can do that with pointers: char c1[] = "Odin"; char* p = c1; p = p + 1; Commented Apr 24, 2021 at 0:26
  • 1
    @Tudor No because strcpy() with overlapped source and destination invokes undefined behavior. Commented Apr 24, 2021 at 0:27

1 Answer 1

1

Quoting the reference for your problem:

Assignment Objects of array type cannot be modified as a whole: even though they are lvalues (e.g. an address of array can be taken), they cannot appear on the left hand side of an assignment operator:

So, since c in your code is an array object i.e. a type of an array, it cannot appear on the left-hand side of an assignment operator.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.