Local and Global Structure in C


You can define structure globally and locally. If the structure is global then it must be placed above all the functions, so that any function can use it. On the other hand, if a structure is defined inside a function then only that function can use the structure.

Source Code

//Local and Global Scope Structure in C Programming
#include<stdio.h>
 
struct student
{
    char *name;
    int age;
    float per;
};
 
void total()
{
   struct mark
   {
       int m1,m2,m3;
   }s;
   s.m1=50;
   s.m2=50;
   s.m3=50;
   printf("\nMark-1        : %d",s.m1);
   printf("\nMark-2        : %d",s.m2);
   printf("\nMark-3        : %d",s.m3);
}
 
int main()
{
    struct student o;
    //struct mark x;
    o.name="Tutor Joes";
    o.age=30;
    o.per=85.5;
 
    printf("\nName        : %s",o.name);
    printf("\nAge         : %d",o.age);
    printf("\nPercent     : %f",o.per);
    total();
    return 0;
}
 
 
To download raw file Click Here

List of Programs


Sample Programs


Switch Case in C


Conditional Operators in C


Goto Statement in C


While Loop Example Programs


Looping Statements in C

For Loop Example Programs


Array Examples in C

One Dimensional Array


Two Dimensional Array in C


String Example Programs in C


Functions Example Programs in C


Learn All in Tamil © Designed & Developed By Tutor Joes