fajar96te said:
When I tried to compile this:
// ==============
#include <stdio.h>
void main()
make that
int main( void )
main() is supposed to return an int and either takes no argumemts
or two (and not an unspecified number, which is the meaning of
not specifying any arguments.
{
char k[4] ;
k = "abc" ;
'k' is an array of chars and you can't assign to an array as
a whole (that holds for all kinds of arrays, not just arrays
of chars). Moreover, what you have on the right hand of the
equal sign is not an array of chars but a pointer to a string
literal (i.e a pointer to a const array of chars), so you have
two things going wrong here - on the one hand you try to assign
to an array and then you have different tyoes on both sides of
teh assignment.
What you may have seen is somthing like
char k[4] = "abc";
The important difference is that this isn't an assignment but
an initialization of an array - and this can only be done while
the array is defined. And that you can use a string literal here
is some special case in C to make it easier to initialize
strigs, without this special case you'd have to write
char k[4] = { 'a', 'b', c', '\0' };
as you have in any other type of array initialization.
Compare this to an int array: an initialization like
int x[3] = { 1, 42, -17 };
int y[3];
is fine, but you can't do neither
x = { 1, 2, 5 };
nor
y = x;
Regards, Jens