Code: //POinters #include using namespace std; int main() { int var = 9; int *ip; double *dp; float *fp; char *ch; ip=&var; //&= address of (saves address of variable var in ip) cout<<"Variable Value "< using namespace std; int main() { int size,i; int *ptr; cout<<"Enter size of an array"<>size; ptr = new int[size]; cout<<"Enter Array Elements to store\n"; for(i=0;i>ptr[i]; } cout<<"Values of Array are\n"; for(i=0;i #include #include #include #include using namespace std; class Cars{ public: string company_name; string model_name; string fuel_type; float milage; double price; public: setData(string cname, string mname, string ftype, float m, double p) { company_name=cname; model_name=mname; fuel_type=ftype; milage=m; price=p; } void displayData() { cout<<"\nCAR PROPERTIES"<
Code:
//POinters
#include<iostream>
using namespace std;
int main()
{
int var = 9;
int *ip;
double *dp;
float *fp;
char *ch;
ip=&var; //&= address of (saves address of variable var in ip)
cout<<"Variable Value "<<var<<endl;
cout<<"Address saved in pointer "<<ip<<endl;
cout<<"Pointer pointing to value "<<*ip<<endl; *ip=50;
cout<<"\nVariable Value "<<var<<endl;
cout<<"Address saved in pointer "<<ip<<endl;
cout<<"Pointer pointing to value "<<*ip<<endl; }
//Dynamic Memory Allocation
#include<iostream>
using namespace std;
int main()
{
int size,i;
int *ptr;
cout<<"Enter size of an array"<<endl;
cin>>size; ptr = new int[size];
cout<<"Enter Array Elements to store\n";
for(i=0;i<size;i++)
{
cin>>ptr[i];
}
cout<<"Values of Array are\n";
for(i=0;i<size;i++)
{
cout<<ptr[i]<<endl;
}
for(i=0;i<size;i++)
{
cout<<"Address of"<<ptr[i]<<"Using Array is "<<ptr[i]<<endl;
}
}
//Concept of classes and objects
#include<iostream>
#include<string>
#include<string.h>
#include<stdio.h>
#include<conio.h>
using namespace std;
class Cars{
public:
string company_name;
string model_name;
string fuel_type;
float milage;
double price;
public:
setData(string cname, string mname, string ftype, float m, double p)
{
company_name=cname;
model_name=mname;
fuel_type=ftype;
milage=m;
price=p;
}
void displayData()
{
cout<<"\nCAR PROPERTIES"<<endl<<endl;
cout<<"Company Name \t"<<company_name<<endl;
cout<<"Modal Name \t"<<model_name<<endl;
cout<<"Fuel Type \t"<<fuel_type<<endl;
cout<<"Milage \t\t"<<milage<<endl;
cout<<"Price \t\t"<<price<<endl;
}
} ;
int main()
{
Cars car1,car2;
car1.setData("Suzuki","Mehran","Manual",2000,800000);
car1.displayData();
car2.setData("Tesle","beta","Electric",10.5,8000000);
car2.displayData();
return 0;
}
Note: Implement the concept of link list by using the above sample codes
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images