This program defines a temp struct that has two members: f and i. It then creates an instance of this struct: t. In main(), a pointer ptr of type temp and t is created. The ptr is assigned the address of t using the address-of operator &ab;.
The program then prints the values of f and i using the pointer ptr and the dereference operator *. The dereference operator is used in combination with the dot operator . to access the members of the struct pointed to by ptr. Overall, this program is an example of how to define and use a pointer to a struct in C++. It creates an instance of the temp struct, creates a pointer to this struct, assigns the address of the struct to the pointer, and then uses the pointer to access and print the values of the struct members
#include<iostream> using namespace std; struct temp { float f=23.34f; int i=10; }; int main() { temp *ptr, t; ptr = &t; cout<<"F :"<<(*ptr).f<<endl; cout<<"I :"<<(*ptr).i<<endl; return 0; }To download raw file Click Here
F :23.34 I :10
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions