Skip to main content

Structure C programming - Used to Store More Then One Type Of Data.

Structure is used to store more then one values in different data types. struct keyword is used to declare the structure.
Syntax
struct structure_name{
int id;
char name[50];
float salary;
};
main()
{
struct structure_name object_of_structure;
}
How To Access Structure Member Variable ?
Create the object of that structure. And access  the values of structure variable using "."(dot operator).
Example
struct emp{
int id;
char name[50];
float salary;
};
main()
{
struct emp e;
printf("Enter the employee details\n");
printf("Id :");
scanf(%d,&e.id);
printf("Name :");
scanf(%d,e.name);
printf("Salary :");
scanf(%f,&e.salary);
printf("\nEmployee details");
printf("\n%d",e.id);
printf("\n%s",e.name);
printf("\n%f",e.salary);
}
Output
Enter the employee details
Id : 25
Name : mrc
Salary : 25000
Employee details
25
mrc
25000
From the above programme we declare the id,name and salary variables inside the structure emp.
Then access member variables of the structures through  "."(Dot operator) .

Comments

Popular posts from this blog

Class is a collection of similar objects. Which have common properties

Class is a collection of similar objects. Which have common properties. Syntax class class_name {        //member functions and variables. } How to create a objects for class class_name c=new class_name; We can access the member variable and member methods using dot operator. c.member_function(); Eg : class bike { void fun() { System.out.println("member method"); } public static void main(String[] args) { bike B=new bike(); B.fun(); } } output member method

Array - Java Programming

//Array Is a Basic Data Structure in Computer Programming. Array Have Continues Memory Allocation in Memory Space. Data Are Stored In Continues memory space . We Access Using the index Of The Element. Index Start From 0 to n-1 //Basic Operations in Array /* traverse search find insert Remove */ class array{ //Traverse A Array public static void traverse( int [] arr){ int n=arr.length; for ( int i= 0 ;i<n;i++){ System.out.println(arr[i]); } } //Find Value By Index public static void findByIndex( int [] arr, int index){ System.out.println(arr[index]); } //Find Index By Value public static void findIndex( int [] arr, int value){ int n=arr.length; for ( int i= 0 ;i<n;i++){ if (arr[i]==value){ System.out.println(i); } } } //Insert Function (Array Copy Method) public static void insert( int [] arr, int index, int v...