Raghav Solutions

Raghav Solutions

Share

25/04/2020

//Demostration of Structure and Union Size Comparision


union unionDemo
{
//defining a union
//char name[10];
float salary;
int id;
} u_instance;

struct structDemo
{
//char name[10];
float salary;
int id;
} s_instance;

int main()
{
printf("size of union = %d bytes", sizeof(u_instance));
printf("\nsize of structure = %d bytes", sizeof(s_instance));
return 0;
}

24/04/2020

//Structure Demostration


/*structure creation*/
struct student
{
char name[50]; // structure member1
int id; // structure member2
char branch[20]; // structure member3
int age; // structure member4
char place[50]; // structure member5
} std; // structure variable
int main()
{
/*Taking information from keyboard and store it by using structure variable std*/
printf("Enter Student Information\n");
printf("----------------------------\n");
printf("enter name :");
scanf("%s",std.name);

printf("enter id :");
scanf("%d",&std.id);

printf("enter branch name :");
scanf("%s",std.branch);

printf("enter age :");
scanf("%d",&std.age);

printf("enter location :");
scanf("%s",std.place);

/*Displaying student information */
//Accessing information by using structure variable std
printf("Displaying Student Information\n");
printf("----------------------------\n");

printf(" name: %s\n", std.name);
printf(" id: %d \n", std.id);
printf(" branch: %s \n", std.branch);
printf(" age: %d\n", std.age);
printf(" place: %s \n", std.place);

return 0;
}

24/04/2020

//Calloc Example



int main()
{
int n, i, *ptr, sum = 0;
printf("Enter number of elements: ");
scanf("%d", &n);
ptr = (int*) calloc(n, sizeof(int));
if(ptr == NULL)
{
printf("Error! memory not allocated.");
exit(0);
}
printf("Enter elements: ");
for(i = 0; i < n; ++i)
{
scanf("%d", ptr + i);
sum += *(ptr + i);
}
printf("Sum = %d", sum);
free(ptr);
return 0;

}

Want your school to be the top-listed School/college in Khargone?
Click here to claim your Sponsored Listing.

Telephone

Website

Address


Khargone
451001

Opening Hours

Monday 5pm - 9pm
Tuesday 5pm - 9pm
Wednesday 5pm - 9pm
Thursday 5pm - 9pm
Friday 5pm - 9pm
Saturday 5pm - 9pm