Q:

String literals in structure is showing an error but when string literals declare as a constant it will not show an error why?

This program is compiled and run but showing error:
ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
#include<iostream>
using namespace std;
struct person{
 char* name;
 char* lastName;
 int age;
};
void show(person temp){
 cout << temp.name << " " << temp.lastName << " age is: " << temp.age;
}
int main(){
// decaring a person    
 person p;
 p.name = "Jayant";
 p.lastName = "Sharma";
 p.age = 18;
//reassigning of p 'name'
 p.name = "Kartik";
 show(p);
 return 0;
}
// output => Kartik age is: 18

But when I declare variables using const compiler not shows an error and reassigning is also done
struct person{
    const char* name;
    const char* lastName;
    int age;
};

reassigning the name 'Kartik' to the same const variable 'name' is done without an error.

A:

I see your confusion about your sample source code. However, I see two questions you did not explicitly state, but implied. So I will answer both!
What are String Literals in C++?
The ISO/IEC C++ standard defines a string literal as an array of const char * , and your sample code violates this definition by declaring your variables name and lastName as having type char * only! Although this isn't the case in the C language see Why is conversion from string constant to 'char*' valid in C but invalid in C++ for more details!
Way are Variables Assigned Even When Declared Const?
The compiler doesn't throw an error at you because you did not utilize the const keyword correctly!
const char* name = "Sharma";

The above code sample states that the value held in variable name is constant, but its address is not!
const char* const name = "Sharma"; 

Now the above code sample states that both the value and address held in variable name is constant!
When you use the member of object operator you are stating that the memory address being manipulated is the address of the object being accessed plus the offset where the data is stored. Therefore, you are indirectly modifying your variables via an address!

