Aspire Faculty ID #12783 · Topic: JECA MCA 2023 · Just now
JECA MCA 2023

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.

Previous 10 Questions — JECA MCA 2023

Nearest first

Next 10 Questions — JECA MCA 2023

Ascending by ID
Ask Your Question or Put Your Review.

loading...