Share on Google+Share on Google+

C Structure example

Structures in C defines the group of contiguous (adjacent) fields, such as records or control blocks.

C Structure example


This section illustrates you the concept of structure in C.

Structures in C defines the group of contiguous (adjacent) fields, such as records or control blocks. A structure is a collection of variables grouped together under a single name. It provides an elegant and powerful way for keeping related data together. 

Structure Declaration:   

struct struct-name{
type field-name; 
type field-name; 
... };

Once the structure is defined, you can declare a structure variable by preceding the variable name by the structure type name. In the given example, a small structure i.e struct is created student and declared three instances of it as shown below.

struct student{
int id;
char *name;
float percentage;

In structures, we have assigned the values to the instances i.e, id, name, percentage in the following way:; = "Angelina";
student3.percentage = 90.5;

Here is the code:


#include <stdio.h>
#include <conio.h>

struct student {
  int id;
  char *name;
  float percentage;
student1, student2, student3;
int main() {
  struct student st;; = "Angelina";
  student3.percentage = 90.5;
  printf(" Id is: %d \n",;
  printf(" Name is: %s \n",;
  printf(" Percentage is: %f \n", student3.percentage);
  return 0;

Output will be displayed as:


Download Source Code


Posted on: February 6, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Discuss: C Structure example   View All Comments

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
August 1, 2012

very nice
September 18, 2012
help to understand plz

struct stud { int roll ; char name[10]; struct stud *next; } what that line means 'struct stud *next'
October 3, 2012

want programme for cheak validation of date
October 19, 2012
c quiz

what is the use of getch in c
November 11, 2012
c progaram

this is good
November 22, 2012
NO So Bad

Good Attempts
rahul sharma
November 24, 2012
structure in c

when some one ask for the simplest example of ...kindly do'nt use the pointer .... difne the sturct example a very simple way so that begners cn understand it easily .............
rinku sehrawat
April 18, 2013

w.a.p for structure record of a student
April 21, 2013
structure in c