Constructor and parameterized constructor

char name[20]
char *n
strcpy(name, n)

this is basically happening where i have a doubt
Why did we define char *n as a pointer variable?

we did so in order to create a string literal.
char *n will create a pointer and it will be assigned the address of string literal.

but it is working even if we just copy the value normally without using pointer.
what is the problem in that?

That’s because char* s=“pointer”;
is similar to
char name[] = “pointer”;
char *s = name;

1 Like