#include <stdio.h>
int main(void){
char c1[], c2[];
c1 = "hello";
c2 = "world";
printf("%s %s", c1, c2);
return 0;
}
What exactly makes it that I cannot use 'char c1[], c2[]'? I have some knowledge in Java and I find C syntax to be rather familiar with it but clearly somethings do not work.
Is there also any reason why char is declared as char variable[] instead of char[] variable? It seems to make more sense like this (Java notation)
c[2] = 'x';and not[2]c = 'x';, so you writechar c[3];and notchar[3] c;.char c1[]- so how many characters do you expect c1 to hold? In C, this makes c1 an array, not a reference to an array like it does in Java.char c1[], An array in C, must be either declared with a specific length or initialized with a char string. I.E. either:char c1[20];orchar c1[] = "hello ";. Strings can only be copied char by char or using a function like:strcpy()Only at variable initialization can a char array be set using=.