Вы находитесь на странице: 1из 3

RAGH INSTITUTE OF TECHNOLOGY

SPECIFICATION:
UNION
(15)(b) C Program to Show Working ability of Structure and Union
ALGORITHM:
Step 1: Start
Step 2: Define structrure job s globally
2.1: Declare variable name,salary,worker_no
Step 3: Denife union job u globally
3.1: Declare variable name,salary,worker_no
Step4: Display sizof
4.1: job s
4.2: job u
Step5: Stop
FLOWCHART

START

Display
sizeof(s),sizeof(u)

stop

STRUCTURE:

UNION:

++++++++++++++++++++++++

++++++++++++++++++++++

Job:- (s)

Job:- (u)

Name

Name

Salary

Salary

Worker_no.

Department of Computer Science & Engg

RAGH INSTITUTE OF TECHNOLOGY

PROGRAM
/*C program to display the working ability of structure and union */
Program name:

// wk15b.c

/* Done By : C-Faculty

Dated: 15/10/2013*/

#include<stdio.h>
struct job
{
char name[32];
float salary;
int worker_no;
}s;
union job1
{
char name[32];
float salary;
int worker_no;
}u;
int main()
{
printf(size of structure is %d,sizeof(s));
printf(size of union is %d,sizeof(u));
return(0);
}
PROCEDURE FOR EXECUTING THE PROGRAM:
Step 1: After typing the program, press ESC button+shift+: and then type wq(to save the
program and quit)
Step 2: Now compile the program by using the following command
cc wk15b.c lcurses -lm
Department of Computer Science & Engg

RAGH INSTITUTE OF TECHNOLOGY

Step 3: Now go for running the program by using the command


./a.out

Step 4: To create an executing file use the command


cc wk15b.c -curses o structuresunion

EXPECTED I/P AND O/P & ORIGINAL OUTPUT:


Size of structure : 40
Size of union : 32
VIVA VOCE QUESTIONS:
1. When we need structures?
Ans: Structures are used when we want to process data that may be of multiple data
types.
2. How structure members called
Ans: Structures have members in the form:
structurename.membername.
3. What is nested structure?
Ans: When a structure is a member of another structure it is called a nested structure.
4. What is Structure of Arrays ?
Ans: We can define structures of arrays or arrays of structures based on the members
which are referred with using dot notations.
5. What is a UNION?
Ans: In a union, the different members share the same memory location.
6. What about memoery size in Union ?
Ans: The total memory allocated to the union is equal to the maximum size of the
member
--xXx--

Department of Computer Science & Engg

Вам также может понравиться