Skip to content
Menu
Code for Java c
  • Home
  • Java
    • Java Examples
    • Java tutorials
  • C
    • C tutorials
    • C Examples
  • C++
    • C++ Tutorials
    • C++ Examples
  • Python
    • Python Tutorials
    • Python Examples
  • About
    • About me
    • contact us
    • disclaimer
    • Privacy Policy
Code for Java c

Structure in C programming languages

Posted on March 25, 2017September 15, 2019

Table of Contents

  • Structure in C programming languages
    • Diclaration of structure
    • Example
    • Creating struct variable
    • method 2
    • Accessing struct variable

Structure in C programming languages

In this tutorial, we will discuss the Structure in C programming languages

the structure is a collection of different type of variables under a single name or unit. Which are grouped together and each element is called member in C programming Language

The structure is a user define or custom data type. Which contains an individual element that can defer in type. that allows to combine data items of a different kind Hence structure can contain integer, float, double etc.

define a structure

When defining a structure, you must use the struct statement or keyword in C to the grouped mixed type of variables

Access a structure

To access any member of s structure, we use the dot(.) member access operator. This operator pointed between the structure variable name and the structure member

Syntex

Diclaration of structure


struct structure_name
{
data_type  variable_name1;   
data_type variable_name 2;
.................
.................
data_type variable_name n;
};

Example

struct student
{
char name[50];
int age;
float fees;
};

Creating struct variable

when a struct variable is declared, storage is not allocated in the memory. if we want to work with the structure variable we must create the structure variable

method 1

create structure variable seperately

struct student
{
char name[50];
int age;
float fees;
}
int main(){
struct student stu1,stu2,p[30];
}

method 2

create structure variable structure definition

struct student
{
char name[50];
int age;
float fees;
}struct student stu1,stu2;

Accessing struct variable


printf|(s1.variable_name_1);
printf|(s1.variable_name_2);
...........
...........
printf|(s1.variable_name_n);

example  – we want to store some information about a student, Student name, Student id, marks and garde We can easily create different variables name, stu.id, marks, age to store this information

Program 1

Structure in C programming languages
Example
Output
Structure in C programming languages
Output
Program 2
Structure in C programming languages
Example
Output

Similar post

Structure in C Language                                 Structure in C++ Language
Structure with function in C Language  Structure with the pointer in C++
 Structure with the pointer in C Language 
Function in C Language      Nested structure  in C access with variable      
Nested function  in C      Structure with function C++  Language

Related

Recent Posts

  • Subtract two numbers using method overriding
  • PHP Star triangle Pattern program
  • Using function or method to Write temperature conversion : Fahrenheit into Celsius
  • Function or method:temperature conversion from Fahrenheit into Celsius – Entered by user
  • Write temperature conversion program: Fahrenheit into Celsius
  • How to write a program to convert Fahrenheit into Celsius

tag

Addition (6) Array (38) C++ language (91) C language (98) c sharp (23) Division (6) Function (29) if else (32) Java language (102) JavaScript (5) loops (137) Multiply (7) Oop (2) patterns (65) PHP (13) Python Language (38) Subtraction (7) temperature (20)

Archives

Categories

Address

Global information technology

Puloly south, PointPedro

Jaffna

Srilanka

©2025 Code for Java c | Powered by SuperbThemes