Answer to Question #193026 in C++ for Ajith M

Question #193026

Develop a C++ program to read the marks and find the total marks of a student using void pointers


1
Expert's answer
2021-05-17T16:43:38-0400
#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.


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog