what is difference between array,strutter,union and pointers

Answer Posted / ravi

structure is collection of different data types.
union is same as the structures, the only difference is in
memory allocation.
struct
{
int a;
float b;
};
struct s;
s.a=10;
s.b=3.0;
printf("%d%f",s.a,s.b);

For the above structure it allocates 2bytes for integer
variable and 4 bytes for flaot variable. so totally it
allocates 6bytes of memory to that structure. we can print
the s.a and s.b values as 10 and 3.0
#include<stdio.h>
union
{
int a;
char ch;
}u;

u.a=100;
u.ch='a';
printf("%d\n%d",u.a,u.ch);


But incase of union, the memory allocated is maximum
memory required among the variables. so only 4 bytes is
allocated to unions.
if u try to print the u.a, u.ch values it prints 97, 97
where the value of u.a is being assigned by u.ch . so we
cannt get value of u.a at last. It wont happen incase of
structures. so mostly we use structures in programming.

Is This Answer Correct ?    31 Yes 6 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain what is the stack?

623


What is fflush() function?

631


Define circular linked list.

560


What is NULL pointer?

668


please can any one suggest me best useful video tutorials on c i am science graduate.please help me.u can email me to sas29@in.com

1314






Write a program to produce the following output: 1 2 3 4 5 6 7 8 9 10

15026


Why is c called c not d or e?

598


Do you have any idea about the use of "auto" keyword?

652


Should I learn data structures in c or python?

567


What is anagram in c?

510


What is the size of enum in c?

606


What is structure packing in c?

593


The purpose of this exercise is to benchmark file writing and reading speed. This exercise is divided into two parts. a). Write a file character by character such that the total file size becomes approximately >10K. After writing close the file handler, open a new stream and read the file character by character. Record both times. Execute this exercise at least 4 times b). Create a buffer capable of storing 100 characters. Now after generating the characters, first store them in the buffer. Once the buffer is filled up, store all the elements in the file. Repeat the process until the total file size becomes approximately >10K.While reading read a while line, store it in buffer and once buffer gets filled up, display the whole buffer. Repeat the exercise at least 4 times with different size of buffer (50, 100, 150 …). Records the times. c). Do an analysis of the differences in times and submit it in class.

1620


design and implement a data structure and performs the following operation with the help of file (included 1000 student marks in 5 sub. and %also) 1.how many students are fail in all 5 subjects (if >35) 2. delete all student data those are fail in all 5 subjects. 3. update the grace marks (5 no. if exam paper is 100 marks) 4. arrange the student data in ascending order basis of marks. 5.insert double of deleted students with marks in the list.

1483


What are the different categories of functions in c?

633