{Quality Online Education Since 2009}


C Programming Structures

Advertisement

Structure is user defined data type in C, which is used to store collection of different kinds of data.

Defining a Structure in C

Syntax:
struct structureName
{
   //member definitions
};
Example:
struct Courses
{
   char  WebSite[50];
   char  Subject[50];
   int   Price;
};

Accessing Structure Members in C

Example:
#include<stdio.h>
#include<string.h>
 
struct Courses
{
   char  WebSite[50];
   char  Subject[50];
   int   Price;
};
 
void main( )
{
   struct Courses C;
   
   //Initialization
   strcpy( C.WebSite, "w3schools.in");
   strcpy( C.Subject, "The C Programming Language"); 
   C.Price = 0;
   
   //Print
   printf( "WebSite : %s\n", C.WebSite);
   printf( "Book Author : %s\n", C.Subject);
   printf( "Book Price : %d\n", C.Price);
}
Program Output:

WebSite : w3schools.in
Book Author : The C Programming Language
Book Price : 0


« Previous Chapter
C Strings
Next Chapter »
C Unions