FreePrograms


C language is a middle level language. It is a structured language. C language is a case sensitive language. All syntax written in c language is in lower case. C is the basis for C++.
  CONTACT US   ABOUT US   PRIVACY  DISCLAIMER

FREE C PROGRAMS 

What is C C vs C++ vs Java Program Structure Data Types in C Basic Rules of C & C++
Functions in C If, Else Conditions Loops in C Switch Case Arrays
Pointers Structures in C Strings in C Command Line Arguments Type Casting
Linked Lists Recursion Binary Trees Inheritance Multiple Inheritance
Templates File I/O Object Oriented Programming Data Structures in C C interview Questions

Structures & Unions in C : - C Programming Tutorial




A structure is a collection of variables under a single name where variables can be of different types.

It contains number of data types grouped together. These data types may or may not be of same type.

how to declare a structure?

struct dvd
{
char name;
float price;
int memory;
};
struct dvd a1,a2,a3; //or simply a1,a2,a3


we can also use structure variables here like this

struct dvd
{
char name[10];
float price;
int memory;
};

struct dvd a1={"Cricket",125,650};
struct dvd a2={"Football",150,1000};
struct dvd a1={"C lang",175,650};




Sample program to show how structures work:

Example :

typedef struct

 {
         char line[64];
         int num;
         int age;

         char hobb[128];

 } person;

We can pass structures as arguments to functions.

We can also make structure within a structure.

struct date 

int day; 
int month; 
int year; 
}; 
struct person

int num; 
char name[12]; 
char address[20]; 
structure date def; 
structure date doa; 
}oldperson, newperson;

Use of Typedef in C language

C provides a facility called typedef for creating new data type names.
example:
typedef int Length;
makes the name Length a synonym for int

typedef means you no longer have to write struct all over the place.Typedefs can make your code more clear. Typedefs can make your code easier to modify

Similarly, typedef can be used to define a class type (structure, union etc). For example:

typedef struct {
int inch;
int cm;
int mm;
} HEIGHT;

Pointers to Structures. Malloc function. Dynamic memory allocation

Structures and Arrays

Nesting of Structures

Unions in C

Unions like structure contain members whose individual data types can be different from one another.

union person

int age; 
float sal; 
char n; 

code;

COPYRIGHT 2009 ALL RIGHTS RESERVED FREECPROGRAMS.COM