Answers for "return pointer to structure from a function in c"

C
1

return pointer to struct in C

typedef struct {
  char name[20];
  int age;
} Info;

Info* GetData() {
  Info *info;

  info = (Info *) malloc( sizeof(Info) );
  scanf("%s", info.name);
  scanf("%d", &info.age);

  return info;
}
Posted by: Guest on May-15-2021
0

pointer inside structure in c

#include<stdio.h>

struct Student
{
   int  *ptr;  //Stores address of integer Variable 
   char *name; //Stores address of Character String
}s1;

int main() 
{

int roll = 20;
s1.ptr   = &roll;
s1.name  = "Pritesh";

printf("\nRoll Number of Student : %d",*s1.ptr);
printf("\nName of Student        : %s",s1.name);

return(0);
}
Posted by: Guest on April-08-2020

Code answers related to "return pointer to structure from a function in c"

Code answers related to "C"

Browse Popular Code Answers by Language