Structure in C Programming

In this tutorial, we are going to discuss what are structure in c programming, how to create structure variables, and how to accessing structure members. So, let’s start with this wonderful concept.

Introduction to Structure in C Programming

C also provides user-defined data types, like predefined data types (int, char, float, etc.). One such user-defined data type structure is. Structures are user-defined data types.

Defining a Structure

The structure is defined using the struct keyword, after this keyword is defined, a unique name of the structure is assigned. The curly braces ({) are then used to create the variables and terminate the program by placing a semicolon (;) after the ending curly bracket (}).

struct struct_Name
{
  structure member 1;
  structure member 2;
  ..................
  structure member N;
};

Creating Structure Variables

These variables can be created with 2 methods.

  • With structure definition
  • Without structure definition

With Structure Definition

When we create variables with the Structure Definition type along with the structure definition, the variables are written by separating them with a comma (,) before the semicolon (;) of the end.

Like:-

struct shoes
{
  int price;
}t1,t2;

Without Structure Definition

When we create variables without structure definition, then we use struct keyword. After using the struct keyword, the name of the structure is defined. You can define unlimited variables by separating from and then before the comma (,).

Like:-

struct shoes t1, t2, t3;

Accessing Structure Members

We access Structure members for two reasons.

  • To assign values to members
  • To print the values of the members as output Whenever we have to access a structure member, we do it using the dot operator. Example -
#include<stdio.h>
/* Defining shoes structure */
struct shoes
{
  int price;
};
int main()
{
  /* Declaring variables of shoes structure */
  struct shoes t1;
  /* Assigning value to price of shoes */
  t1.price=999;
  printf(“The Price of the shoes is: %d”,t1.price);
return 0;
}

Output

The price of the shoes is: 999

Originally posted on - Structure in C Programming

To view or add a comment, sign in

More articles by Alimam Miya

  • Elevate Your CAT Preparation with iQuanta's CAT Online Course

    Are you preparing for CAT 2025 and looking for the best online course to boost your chances of success? iQuanta’s CAT…

  • Best CAT Score Calculator 2024

    The Common Admission Test (CAT) is a crucial milestone for MBA aspirants aiming for prestigious institutes like IIMs…

  • Top 10 Pharma Companies in India 2024

    In this will talk about the Top 10 Pharma Companies in India. India’s pharmaceutical assiduity has surfaced as a global…

  • Top 10 Credit Card Companies in India 2025

    This article will talk about the Top 10 Credit Card Companies in India. In the dynamic geography of India’s fiscal…

  • Top Real Estate Companies in India 2024

    This article will talk about the Top Real Estate Companies in India 2024. The real estate region in India has witnessed…

    1 Comment
  • Top Real Estate Companies in Kolkata 2024

    This article will talk about the Top Real Estate Companies in Kolkata. Kolkata, the artistic locus of India, is going…

  • Top Real Estate Companies in Delhi 2025

    This article will talk about the Top Real Estate Companies in Delhi. Delhi, the heart of India, not only serves as the…

    1 Comment
  • Hostinger Coupon Codes 2024 [60% Plan Discount]

    Looking for an affordable yet powerful hosting solution? Hostinger is one of the leading web hosting providers known…

  • 5 Best CAT Online Coaching in Gurugram

    Preparing for the Common Admission Test (CAT) can be a daunting task, especially with the myriad of coaching options…

  • CAT Mock Tests Series - Boost Your CAT Preparation

    Preparing for the Common Admission Test (CAT) can be a daunting task, but with the right resources and strategy, it can…

Insights from the community

Others also viewed

Explore topics