The below program is having two structures. I don't understand how I can pass value from one structure variable to another structure variable while using pointers
#include <stdio.h>
typedef struct {
int c;
char d;
}bob;
typedef struct {
int c;
char d;
}anna;
//expecting 'bob' type variable
void fun(bob *var2)
{
printf("var2->c=%d\n",var2->c);
printf("var2->d=%c\n",var2->d);
}
int main()
{
anna var1;
var1.c=2;
var1.d='c';
fun(&var1);//passing 'anna' type pointer
return 0;
}
...but if I change the program to pass values using normal variables, it gives compilation error.
#include <stdio.h>
typedef struct {
int c;
char d;
}bob;
typedef struct {
int c;
char d;
}anna;
//expecting a variable of type 'bob'
void fun(bob var2)
{
printf("var2.c=%d\n",var2.c);
printf("var2.d=%c\n",var2.d);
}
int main()
{
anna var1;
var1.c=2;
var1.d='c';
fun(var1);//passing a variable of type 'anna'
return 0;
}
What is the logic behind this?