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
while loop contains parts a) initialisation, evalution of an expression,increment /decrement b) initialisation, increment/decrement c) condition evalution d) none of the above
What are enums in c?
Why is c so important?
write a c program to print the next of a particular no without using the arithmetic operator or looping statements?
What is the difference between near, far and huge pointers?
List the difference between a While & Do While loops?
Differentiate between ordinary variable and pointer in c.
What are void pointers in c?
Why isnt there a numbered, multi-level break statement to break out
What is the difference between ++a and a++?
What do you mean by keywords in c?
What are 3 types of structures?
What are the types of operators in c?
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
Is fortran still used in 2018?