Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

assigning char pointer to char and char array variable

Tags:

c

char

pointers

Why is the following ok?

    char *a;
    char b[]="asdf";
    a=b;

But the following is not?

    char a[10];
    char b[]="asdf";
    a=b;

The above gives error: incompatible types in assignment.

like image 341
Majid alDosari Avatar asked Nov 30 '25 23:11

Majid alDosari


1 Answers

Both are not ok.

Maybe you were attempting ,

char *a;
char b[]="asdf";
a=b;
like image 163
Barath Ravikumar Avatar answered Dec 03 '25 14:12

Barath Ravikumar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!