Develop a C++ program to read the marks and find the total marks of a student using void pointers
#include<iostream>
using namespace std;
int main()
{
int p,c,m;
cout<<"Enter your marks in physics, chemistry and maths : ";
cin>>p>>c>>m;
void *p1,*c1,*m1;
p1=&p;
c1=&c;
m1=&m;
int total;
total=p+c+m;
cout<<"\nTotal marks in all subjects = "<<total;
cout<<"\nAddress of p variable "<<p1;
cout<<"\nAddress of c variable "<<c1;
cout<<"\nAddress of m variable "<<m1;
}
The void type comprises an empty set of values; it is an incomplete type that cannot be completed. Since void is an incomplete type, it is not an object type. Therefore it is not a valid operand to an addition operation. Therefore you cannot perform pointer arithmetic on a void pointer.
Comments
Leave a comment