Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 26-11-2009
Member
 
Join Date: Nov 2009
Posts: 140
What is structure in C programming?

Hi Friends,

According to me "Structure" is the most difficult part of the C programming. I have read somewhere that Structure is a type of the user defined data type, Is it true? OR it is similar to the "Class" from object oriented programming

Anybody aware about structure in C programming? Please help me to understand the concept of the Structure from C language.

I will appreciate you help...
Reply With Quote
  #2  
Old 26-11-2009
Member
 
Join Date: Apr 2008
Posts: 1,948
Re: What is structure in C programming?

Hi friend,

In C programming structure is behaves like record. Following is the syntax for the Stucture:
Quote:
struct nameOfstruct { type nameOffield; type nameOffield; type nameOffield;... }
Example:

Quote:
struct EMP { char NAME[20]; int Sal; }
Reply With Quote
  #3  
Old 26-11-2009
Member
 
Join Date: May 2008
Posts: 2,008
Re: What is structure in C programming?

Hi,

Please go through the below example of the structure, in which program will read as well as print the 150 employee records:

Quote:
#include <stdio.h>
#define SIZE 150

typedef struct emp_type {
char name[20];
int ID;
} emp_type;

void print_empt(emp_type *s)
{
printf("Name: %s\n",
s->name);
printf("ID: %d\n", s->ID);
}

emp_type *
read_emp(emp_type *s)
{ int ID;
char name[20];

printf("Enter ID and name\n");
if (scanf("%d %19s",
&ID, name) == EOF)
return NULL;
s->ID = ID;
strcpy(s->name, name);
return s;
}

int main(int argc, char *argv[])
{
emp_type employee[SIZE];
int count = 0;
int n;

while (count < SIZE)
{
if (read_emp(emp +
count) == NULL)
break;
count++;
}

for (n = 0; n < count; n++)
print_emp(employee + n);
exit(0);
}
Reply With Quote
  #4  
Old 26-11-2009
Member
 
Join Date: Apr 2008
Posts: 2,001
Re: What is structure in C programming?

Group of many variable within a single name is referred as Structure in C.i.e a structure is the easy method of biding many parts of interrelated
information.

Structures is defined using keyword known as struct. See below example:

Quote:
struct location{
int home_number;
char road_name[30];
char city[40];
};
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "What is structure in C programming?"
Thread Thread Starter Forum Replies Last Post
Socket programming: Is any new Programming Language? Kushan Software Development 3 14-11-2009 11:13 AM
Addition of a structure Hashim Software Development 3 21-10-2009 10:08 PM
Pointer to structure in C Jamaima Software Development 3 08-10-2009 03:30 PM
JetBrains Introduces a New Programming Paradigm With its Meta Programming System JoeFrat Software Development 3 13-12-2008 01:49 PM
Structure of ntds.dit Griffiths Active Directory 3 29-11-2008 01:40 AM


All times are GMT +5.5. The time now is 03:38 AM.