C programming | Nested structure | Array, function and pointer of structure|| structure Part-II

 Programming codester 

Structure [part-II] 

In part 1 of structure we learnt: 

  • Fundamentals of structure 
  • Syntax of structure 
  • Uses of structure 
  • Importance of structure 
  • And basic program of structure 

Now it’s time to learn array and function of structure. 

So first we will complete array of structure. 

ARRAY OF STRUCTURE: 

  • An array of structres in C can be defined as the collection of multiple structures variables where each variable contains information about different entities. The array of structures in C are used to store information about multiple entities of different data types.  
  • The array of structures in C are used to store information about multiple entities of different data types. 
  • The array of structures is also known as the collection of structures. 
  • SYNTAX OF ARRAY OF STRUCTURE: 

 

So , now ,lets see example of array of structure. 

  • Write a program to read and display N student information using array of structure. 

 

OUTPUT: 

 

Now lets see function of structure!! 

  • FUNCTION OF STRUCTURE: 

Here's how you can return structure from a function: 

In function of structure make a function with structure! 

  • A structure can be passed to any function from main function or from any sub function. 

  • Structure definition will be available within the function only. 

  • It won’t be available to other functions unless it is passed to those functions by value or by address(reference). 

  • Else, we have to declare structure variable as global variable. That means, structure variable should be declared outside the main function. So, this structure will be visible to all the functions in a C program. 

EXAMPLES 

  • Write a program to declare time structure and read two different time period and display sum of it using function. 

 

OUTPUT: 

 

Structure using Pointer 

Reference/address of structure object is passed as function argument to the definition of function. 

EXAMPLE: 

 

OUTPUT: 

 

Nested Structure 

  • When a structure contains another structure, it is called nested structure. 
  • For example, we have two structures named Address and Student. To make Address nested to Student, we have to define Address structure before and outside Student structure and create an object of Address structure inside Student structure. 

 

Write a program to read and display student information using nested of structure. 

Part-1 

Inserting image... 

Part-2 

 

OUTPUTL: 

 

So,guys today we completed structure! 

Now we will start function and loop in the next tutorial! 

If you didn’t watch my previous tutorial I mention all links go and watch! 

  1. Fundamentals of C:  
  2. Compiler and interpretrer: 
  3. Flowchart and algorithm: 
  4. Technology: 
Today's question:
Functions can return enumeration constants in C?
a) true
b) false
c) depends on the compiler
d) depends on the standard
Answer is a.

Learn and explore! 

 

Comments

Popular posts from this blog

C programming | Printf and scanf ||

C programming | structure | Fundamentals of Structure

C programming | Fundamentals & Basic information

Basic question related programming || c programming || embedded programming

C++ || Operators with c++

C++ || string with c++ || Part - 1

Compiler & Interpreter | difference and explanation

c++|operators with c++|variables||

C++(oop)| Fundamentals | Concepts||