-->
Showing posts with label how to initialize data using struct. Show all posts
Showing posts with label how to initialize data using struct. Show all posts

program to initialize data with struct.

using codeblocks
----------------------------------------------------------------------------------------------------------------------
// program to initialize data in struct            //comment abt. program
#include <stdio.h>                                 //header file
struct data                                        //struct tag named data
{
    char name[80];                                //member1 of struct
    char address[80];                             //member2 of struct
    int roll;                                     //member3 of struct

}access={"rajan","Kalanki",34}; //'access' is a variable to access members. rajan,kalanki and 34 are                                                              //data.

int main()
{

   puts("name is\n");
   puts(access.name);                             //accessing member with period operator
   puts("address is\n");
   puts(access.address);                          //accessing member with period operator
   puts("roll number is\n");
   printf("%d",access.roll);                     //accessing member with period operator

    return 0;
}

------------------------------------------------------------------------------------------
or
--------------------------------------------------------------------------------
using codeblocks
----------------------------------------------------------------------------------------------------------------------
// program to initialize data in struct            //comment abt. program
#include <stdio.h>                                 //header file
struct data                                        //struct tag named data
{
    char name[80];                                //member1 of struct
    char address[80];                             //member2 of struct
    int roll;                                     //member3 of struct

};
struct data access={"rajan","Kalanki",34}; //'access' is a variable to access members. rajan,kalanki                                                                           //and 34 are    data.

int main()
{

   puts("name is\n");
   puts(access.name);                             //accessing member with period operator
   puts("address is\n");
   puts(access.address);                          //accessing member with period operator
   puts("roll number is\n");
   printf("%d",access.roll);                     //accessing member with period operator

    return 0;
}

------------------------------------------------------------------------------------------
using turbo c++
--------------------------------------------------------------------------------

// program to initialize data in struct            //comment abt. program
#include <stdio.h>                                 //header file
#include<conio.h>                                //header file
struct data                                        //struct tag named data
{
    char name[80];                                //member1 of struct
    char address[80];                             //member2 of struct
    int roll;                                     //member3 of struct

}access={"rajan","Kalanki",34}; //'access' is a variable to access members. rajan,kalanki and 34 are                                                              //data.

int main()
{

   puts("name is\n");
   puts(access.name);                             //accessing member with period operator
   puts("address is\n");
   puts(access.address);                          //accessing member with period operator
   puts("roll number is\n");
   printf("%d",access.roll);                     //accessing member with period operator
   getch();
    return 0;
}