Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: accessing elements in char array initializer not working with char

Tags:

c

char

I am new to C. I just want to know why initializing the array of int with int is working and why initializing an array of char with char is not working. Or am I wrong thinking that "1" is a char?

#include <stdio.h>

int main()
{
     int incoming_message_test[2] = {1, 2}; // why does this work?
     char incoming_message[2] = {"1", "2"}; // why does this not work?
   
     return 0;
}
like image 887
TSR Avatar asked Feb 17 '26 07:02

TSR


1 Answers

You must change "1", "2" with '1', '2'

like image 156
ABR Avatar answered Feb 19 '26 21:02

ABR



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!