Aspire's Library

A Place for Latest Exam wise Questions, Videos, Previous Year Papers,
Study Stuff for MCA Examinations - NIMCET

Previous Year Question (PYQs)



What is the output of the following program ?
#include <iostream>
using namespace std;
struct demo
{
    int var;
};
int main()
{
    demo str;
    demo *ptr;

    str.var = 100;
    ptr = &str;
    cout << ptr->var;
    return 0;
}






Solution

Output:
100
Explanation:

str.var = 100; assigns 100 to the structure variable.

ptr = &str; makes the pointer point to str.

ptr->var accesses the member var of structure str via pointer.

Hence it prints 100.



Online Test Series,
Information About Examination,
Syllabus, Notification
and More.

Click Here to
View More


Online Test Series,
Information About Examination,
Syllabus, Notification
and More.

Click Here to
View More

Ask Your Question or Put Your Review.

loading...