♦ C Structures
♣ About C Structures
Structures are essential a programming language, to define a custom variable type which can store multiple data types for convinience.♣ C Structures Syntax
Below is the representation of C Structure Syntax.Basic Syntax
struct Structure_Name{ datatype1 attribute1; datatype2 attribute2; datatype3 attribute3; . . methodDataType1 method1(arguments1){ //method1 codeblock } methodDataType2 method2(arguments2){ //method2 codeblock } . . . };
Syntax Explanation:
Structure_Name: name of the structure, note that first letter should be capital
datatype1, datatype2, datatype3, .. : data types of the attributes of the structure
attribute1, attribute2, attribute3, .. : names of the attributes of the structure
methodDataType1, methodDataType2, ... : data types of the returned values of the methods of the structures
//method1 codeblock, //method2 codeblock, ... : the code for the methods of structure with return statements
datatype1, datatype2, datatype3, .. : data types of the attributes of the structure
attribute1, attribute2, attribute3, .. : names of the attributes of the structure
methodDataType1, methodDataType2, ... : data types of the returned values of the methods of the structures
//method1 codeblock, //method2 codeblock, ... : the code for the methods of structure with return statements
♣ Example1: Initializing a Structure in C
In this example, we will Structurize a point variable. Example
Input:
Output:
♣ Example2: Assignment of Structure in C
In this example, there is an Assignment of point x and y. Example
Input:
Output: