Friday 23, June 2017
Welcome Guest, Register | Login  
      Home    |    Tutorials    |    Free Ebooks    |    Free Scripts    |    Articles    |    Blog     |    About Us    |    Contact Us

Structures and Unions

A structure is a collection of variables under a single name. These variables can be of different types, and each has a name which is used to select it from the structure. A structure is a convenient way of grouping several pieces of related information together.

 

Declaring Structures

struct mystruct
{
    int numb;
    char ch;
}

 

Structure has name mystruct and it contains two variables: an integer named numb and a character named ch.

 

Declaring structure variable

 

struct mystruct s1;

 

Accessing Member Variables

 

s1.numb=12;

s1.ch=’b’;

printf(“\ns1.numb=%d”,s1.numb);

printf(“\ns1.ch=%c”,s1.ch);

 

typedef can also be used with structures. The following creates a new type sb which is of type struct chk and can be initialised as usual:

  typedef struct chk
                                    {
                                    char name[50];
                                    int magazinesize;
                                    float calibre;
                                    } sb;
 
                         ab arnies={"adam",30,7};

Unions:

A union is an object that can hold any one of a set of named members. The members of the named set can be of any data type. Members are overlaid in storage. The storage allocated for a union is the storage required for the largest member of the union, plus any padding required for the union to end at a natural boundary of its strictest member.

 

union {
      char n;
      int age;
      float weight;
      } people;
 
people.n='g';
people.age=26;
people.weight=64;

 
     
   
C Language Tutorial
 
  Introduction
Introduction
  First Program
First Program
  Constants and Variables
Constants and Variables
  Loops
Loops
  Control Structure
Control Structure
  Functions
Functions
  Pointers
Pointers
  Arrays
Arrays
  Strings
Strings
  Structures and Unions
Structures and Unions
  File Handling
File Handling
  Graphics
Graphics
 
 
 
Web Designing Tutorials
  HTML Tutorial
HTML Tutorial
  DHTML Tutorial
DHTML  Tutorial
  CSS Tutorial
CSS Tutorial
  XHTML Tutorial
XHTML Tutorial
 
Programming Languages Tutorials
  C Language Tutorial
C Language Tutorial
  C++ Tutorial
C++ Tutorial
  Java Language Tutorial
Java Language Tutorial
  Data Structure Theory Tutorial
Data Structure Theory Tutorial
 
Server Side Scripting Tutorials
  PHP Tutorial
PHP Tutorial
  SQL Tutorial
SQL Tutorial
  ASP Tutorial
ASP Tutorial
 
Client Side Scripting Tutorials
  JavaScript Tutorial
JavaScript Tutorial
  VBScript Tutorial
VBScript Tutorial
 
 
 
POPULAR E-BOOKS
 
Download Wealthy Wal s Guide to Making Money Online Ebook Wealthy Wal s Guide to Making Money Online
   
Download An Introduction to GCC  Ebook An Introduction to GCC
   
Download How To Accelerate Your Internet - A practical guide to Bandwidth Management and Optimisation using Open Source Software Ebook How To Accelerate Your Internet - A practical guide to Bandwidth Management and Optimisation using Open Source Software
   
Download Credit Made EZ  Ebook Credit Made EZ
   
Download Completing the Sale Successfully Ebook Completing the Sale Successfully
   
     
Studiesinn.com 2017 All Rights Reserved.
 
Website Designed & Developed by TechXprtz