Structure in C
In this tutorial, we will cover all the essential concepts related to structures in C, including how to declare, initialize, and access structures. We will also explore how structures can be used for passing complex data types to functions and how to create arrays of structures.
You will learn about various operations that can be performed on structures, such as copying and comparing structures, and how to create nested structures. Additionally, we will also cover the concept of Union, which is a similar concept to structures but with some significant differences.
We will provide you with easy-to-understand examples and clear explanations, making it simple for you to follow along and learn at your own pace. By the end of this tutorial, you will have a thorough understanding of Structures and Unions in C programming language.
So whether you are a beginner or an experienced programmer, this tutorial will equip you with the knowledge and skills needed to utilize Structures and Unions in your programming tasks effectively.
What is Structure?
Structure in c is a user-defined data type that enables us to store the collection of different data types.
Syntax:
struct structureName {
dataType member1;
dataType member2;
...
};
int main() {
struct Student p1,p2;
return 0;
}
Access Member:
p1.name;
#include <stdio.h>
#include <string.h>
struct Book
{
char title[20];
char author[20];
};
int main(){
struct Book b1;
strcpy(b1.title,"C programming");
strcpy(b1.author,"Dennis Ritchie");
printf("Book Title: %s\n",b1.title);
printf("Book Author: %s",b1.author);
return 0;
}
0 Comments