1)Please correct me if anything written in comment // is wrong
2) also tell me why why did ABC getdata()and ABC & getdata() both are true as return type
#include<stdio.h>
struct ABC
{
int x;
ABC getdata()//ABC & getdata() is also true
{
ABC *obj;
obj->x=10;
return *obj;//same as returning in normal_variable()
}
};
//because NV is int so return type is int
int normal_variable(int *p)//int & normal_variable is also true
{
(*p)++;
return *p;//because NV is variable so NV=*p
}
//as NVP is int* so return type is int*
int * variable_pointer(int *p)
{
(*p)++;
return p;//NVP=p
}
int main()
{
int x=5;
int NV;
int *NVP;
NV = normal_variable(&x);
printf("%d\n",NV);
x=5;
NVP=variable_pointer(&x);
printf("%d\n",*NVP);
x=5;
*NVP=normal_variable(&x);
printf("%d\n",*NVP);
ABC obj,obj1;
obj1=obj.getdata();
printf("%d\n",obj1.x);
}
Output:-6
6
6
10
[Finished in 0.1s]