You are here:

C/C language

Advertisement


Question
hell Prince M Premnath will u plz tell me about functions and structure with a simple examplr?

Answer
Dear qamar ul islam!

Function is a set of valid C statements , that used to perform a given task , whereas a structure is simply a memory location used to store different type of data's consecutively .

Eg for function !

here i present a simple function ,
void foo()
{
   printf("Hello world!");
}

This is a simple function , its objective is to display the text "Hello World!" , this operation is quit simple ,functions are used to perform complex operations , and provides lot of advanteges

the above function can be used in main() as follows
void main()
{
  foo();
}

STRUCTURE!
  As i said earlier structure used to store different type of data's consecutively

int values can be stored in int data type similarly for float and other available data types  

   In a real time application a subject exhibits different properties say( A customer ia s subject his properties are his name , age , a/c no and so on ) there is no datatype available by default to store this type of MIXED data
 C provide a best tool to solve this problem Ie : by collecting required data types as a group called structure!

 a structure for the above said subject can be defined as follows
struct customer
{
  int CustID;
  char name[202];
  int age;
  float balance;
};

struct customer c;

So all the information regarding a customer can be stored in a single data type ( in this case the variable is C ).

Note : Structure can also used to store numerous number of customers if its used as an array !


Regards!
Prince M. Premnath.

C

All Answers


Answers by Expert:


Ask Experts

Volunteer


Prince M. Premnath

Expertise


I'm sure that I can solve any doubts in Turbo C ,Graphics Programing ,Mouse, Hardware Programming ,File System ,Interrupts, BIOS handling , TSR Programming , General Concepts in C Language, handling inline Assembly statements

Experience

Research over 6+ Years

Organizations
CG-VAK Softwares and Exports Limited

Education/Credentials
Masters in Computer Applications

©2012 About.com, a part of The New York Times Company. All rights reserved.