Initialize character array in
struct:
I've seen that there arises problem
when initializing character type array in structs. Let me tell you the correct
way.
#include <iostream>
using namespace std;
struct a{
double id;
int tag;
char array[10];
};
int main(){
a var1, var2;
var1.id = 100.0;
var1.tag = 1;
var1.array = "The City"; //WRONG.
//Correct: strcpy(var1.array,"The City");
var2 = var1;
cout << "var2.id = " << var2.id << endl;
cout << "var2.tag = " << var2.tag << endl;
cout << "var2.array = " << var2.array << endl;
return 0;
}
No comments:
Post a Comment