There is no error while compiling but there is a run time error anyone knows why?
#include<iostream>
using namespace std;
struct StrCar{
char RegCode[10];
int PhoneNo;
char Colour[10];
int Model;
};
int main(){
StrCar *Car[1]={0}; //declaring array of pointers
when using dynamic arrays, you must declare a pointer to the base address, then use the new keyword to allocate [x*sizeof(datatype)] number of bytes on the heap.
so in your case, you need StrCar *Car; so you have a variable pointing to the datatype StrCar,
and the Car = new StrCar[1]; to allocate enough memory on the heap to store 1 car struct. and by setting your pointer '=' to the newly allocated memory space on the heap, you can now access it.
#include <iostream>
#include <iomanip>
usingnamespace std;
struct StrCar
{
char RegCode[10];
int PhoneNo;
char Colour[10];
int Model;
};
int main(){
StrCar **Car; //Pointer to pointer or type StrCar
Car = new StrCar *[10]; //Declares array of pointers
Car[0] = new StrCar; //Initializes car[0] only
cout<<"enter1:"<<endl;
cin >> Car[0]->RegCode;
cout<<"you entered"<<endl;
cout<<Car[0]->RegCode<<endl;
system("pause");
return 0;
}