> Online tutorial

function in c

user defined function
Need for user defined function:
As pointed out that main is a specially recongized fuction in c.ever y fuction program must have main function to

indicate where the functionhas to execution has to begin its execution.



copying structures in c






#include<stdio.h>

#include<conio.h>

struct detail

{

char name[10];

int page;

};

void main()

{

int x;

struct detail m1={"anbu",10};

struct detail m2={"kan",20};

x=((m1.name==m2.name)&&(m1.page==m2.page))?1:0;

if(x==1)

{
printf("correct");

}

else

{

printf("bad");

}

getch();

}

Output:

bad

initializing structure variables in c

initializing structure variables in c
Like any other datatype ,a structure variable can be initializes at compil time

Syntax:
main()

{

struct
{
datatype variable;

datatype variable1;

}

student ={60,70,90};

}

This assigns values 60 to student.variabel and 70,90 to student.variable2 .

there is a one to one correspondence between the member and their initializing values

initializing Variabel
struct st_record

{

int wt;

float ht;

}student1={60,70,90};

main()
{
structst_record sstudent2={53,170.60};

}

Explanation
1.1.the keyword struct

2.the structure tag name

3.List terminated semicolon

4.The assignment operator=

Rule of initializing variable
1.we cannot initialize individual member inside the structure template

2.The order of values enclosed in braces must matchthe order of member in

the structure definition

3.zero for integer and floating point number

4.'\0' for character and string




declaring structure variables



Declaring structure variable

after defining a structure format we can declare vraiable of data type.

A structure variabel declaration is similar to the of variable of any other data

type.it includes the following elements

1.the keyword struct
2.the structure tag name

3.List of names separated of commas

For example ,the statement

struct book_bank,book1,book2,book3

declares book1,book2,book3 as variable of type struct book_bank

Declaration:
struct book_bank

{

char title[20];

char author[10;

int pages;

};

struct book_bank,book1,book2,book3;

remember that the member of a structure themselves are not variable .they

don't occupy any memory until they are associated with structure variable as book1

Type Defined structure:
we can use the keyword typedef to define a structure as follow

typedef struct

{


type member1;

type member2;

}type_name;

the type_name represent structure definition assoicated with it and therefore can beused to declare structure variable as shown
type_namevar1,var2;





stucture in c



unlike arrays ,structure must be defined first for their format that may be used later to declare structure variable.

syntax
struct book_bank

{

char title[20];

char author[10];

int pages;

};






Explanation
the keyword struct keyword declares a structure to hold the details of three data fields,namely title,author,pages.

these fields are called structure element or member

general form of structure

struct tag_line

{

data type member1;

data type member2;

};