Posts

Showing posts from March, 2023

Demonstrate the use of self-reference structure

Image
  Example : Write a program to demonstrate the use of self-reference structure. #include<stdio.h> #include<conio.h> struct node // here node is name of structure { int x; // member char y; struct node *p; // Here p is pointer type member };   int main() { struct node obj1;        // here obj1 is variable structure // Initialization value to x and y member using first variable obj1.p = NULL; obj1.x = 10; obj1.y = 20; struct node obj2; // here obj2 is variable   // Initialization value to x and y member using second variable obj2.p = NULL; obj2.x = 30; obj2.y = 40; // Linking obj1 and obj2 variables obj1.p = &obj2; //Initialization obj2 to obj1 // Accessing data members of ob2 using ob1 printf("Value of x is using object first:%d", obj1.p->x); printf("\n Value of y is using object first:%d", obj1.p->y); getch(); } Output : 

write a program in program notebook for pass by reference to user defined function

Image
  For Example: Write a program to create structure as employee and accept idno, name of employee , city and salary of employee and pass it to the user defined function by using pass by reference  #include<stdio.h> #include<conio.h> struct employee { int idno; char ename[20]; char city[10]; float salary; }; void output(struct employee *ep); int   main() { struct employee e; printf("\n Enter ID number:"); scanf("%d",&e.idno); printf("\n Enter name of Employee: "); scanf("%s",&e.ename); printf("\n Enter City of Employee:"); scanf("%s",&e.city); printf("\n Enter Salary of Employee"); scanf("%f",&e.salary); output(&e); // Calling function (passing structure variable stud as argument) getch(); return 0; } void output(struct employee *ep)    //Function definition { printf("\n Employee Id   is: %d",ep->idno); printf...

Write a program in Program Notebook......

Image
  For Exmaple: Write a program to create structure as employee and accept idno, name of employee , city and salary of employee and pass it to the user defined function by using call by value #include <stdio.h> #include<conio.h> struct employee { int idno; char ename[20]; char city[10]; float salary; }; void output(struct employee ep); void main() { struct employee e; printf("\n Enter ID number:"); scanf("%d",&e.idno); printf("\n Enter name of Employee: "); scanf("%s",&e.ename); printf("\n Enter City of Employee:"); scanf("%s",&e.city); printf("\n Enter Salary of Employee"); scanf("%s",&e.salary); output(e); // Calling function (passing structure variable stud as argument) getch(); } void output(struct employee eu)    //Function definition { printf("\n Employee Id   is: %d",ep.idno); printf("\n Name of Employee...

Write program in Program notebook ...................

Image
  For Example : Write a program to create samp structure and accept x and y   value and update x variable in function #include <stdio.h> #include<conio.h> struct samp                  //Here samp   is name of structure { int x;   //member int y; }; void uf(struct samp *p);             //Here p is the pointer variable of structure, p is point to s structure variable void main() { struct samp s;         // Here s a structure variable printf("\n Enter value for x:"); scanf("%d", &s.x); printf("\n Enter value for y:"); scanf("%d", &s.y); uf(&s);     // Here function call printf("\n Value of x is:%d",s.x); getch(); } void uf(struct samp *p)    //Function definition { printf("\n Value of X is : %d",p->x); prin...

passing structure to a function by address

Image
  Instruction: Program write in notes notebook  For Example: Write a program to demonstrate the use of passing structure to a function by address #include<stdio.h> #include<conio.h> struct student                    //Here student is a structure { int rollno; char sname[20]; char sclass[20]; };   void display(struct student *stu);             //Here stu is the pointer variable of structure, stud is point to s structure variable // function prototype should be below to the structure declaration otherwise compiler shows error void main() {               struct student s;              // Here s a structure variable           ...

pointer to structure using (-> operator)

Image
  For Example: Write a program to demonstrate the use of pointer to structure using (-> operator) #include<stdio.h> #include<conio.h> struct student    //here student is structure name { int roll_no; //members char sname[20]; char sclass[20]; char city[20]; char dob[10]; float marks; }; void main() { struct student s,*ptr;     //Here s is simple variable of structure and *ptr is pointer variable                     ptr=&s;           //initialized pointer to structure variable                   printf("\n Enter Roll Number: ");                   scanf("%d",&s.roll_no);        ...

Pointer to Structure

Image
  Pointer to Structure: A pointer is a variable which hold the starting address of another variable, it may be of type integer, float and character. Similarly, if the variable is of structure type there for accessing the starting address of structure, we must declare pointer for a structure variable. This pointer is also called as structure to pointer. Pointer to structure  can be declared as follow : Syntax: struct <structure_name> { //structure elements/Members ; } ; struct <structure_name> <structure_variable>,* <pointer_variable_name>;   For example: struct student     // here student is name of student  { int rollno;     // Structure members                char sname[50];               char sclass[20];          ...

Advanced Programming Programs

Image
   Array of Structure- Example: Write a program to demonstrate the use of array of structure. #include<stdio.h> #include<conio.h> struct student { int rollno; char sname[50]; char sclass[20]; char city[30]; float marks; }; main() { int i; struct student s[4];    //structure declaring printf("--Enter information of students--\n"); for( i=0;i<4;i++) { printf("Enter Roll Number: "); scanf("%d",&s[i].rollno); printf("Enter Name of Student: "); scanf("%s",&s[i].sname); printf("Enter Class of Student: "); scanf("%s",&s[i].sclass); printf("Enter City: "); scanf("%s",&s[i].city); printf("Enter Student Marks: "); scanf("%f",&s[i].marks); } for(i=0;i<4;i++) { printf("\n ------------------"); printf("\n Student Record:%d \n",i+1); printf("\n ------------------"); printf("\n Roll is : %d\n",s[i].rollno); prin...