Académique Documents
Professionnel Documents
Culture Documents
Structure, like a record, is a collection of one or more variables, usually of different types, grouped together under a single name. A structure let us use as a unit instead of separate entities. For example employee contains empno, ename and salary.
Declaring sturcuture
A structure declaration create format that may be used to declare structure variables.
Struct <tag name> {
Datatype1 var1,var2,.varn;
...
Datatypen var1,var2,.varn; };
Declaring Structures
Does Not Reserve Space
Reserves Space struct my_example { int label; char letter; char name[20]; } mystruct ;
*/
MEANING Assign emp2 to emp1 Compare all members of emp1 and emp2 and returns 1 if they are equal else 0 Return 1 if all members are not equal, other wise zero
Emp1!=emp2
Not all compilers these operations in such cases individual member can be compared using logical operators
Array of structures Nested structures Structures and functions Structure Pointers Self-Referential Structures
Unions
Unions are like structures which together a number of variables The way the two treat these variables entirely different unlike structure the memory will be allocated for the largest element in the union. All the members of the union shares this common area. They are useful for application with multiple members, where values need not be assigned to all of the members simultaneously.
Syntax
union tag_name { Data_type member1; Data_type member2; .. Data_type membern; }union_variables;
Enumeration
Enumeration is a user-defined data type. It is defined using the keyword enum and the syntax is:
enum tag_name {name_0, , name_n} ;
The tag_name is not used directly. The names in the braces are symbolic constants that take on integer values from zero through n. As an example, the statement:
enum colors { red, yellow, green } ;
creates three constants. red is assigned the value 0, yellow is assigned 1 and green is assigned 2.
Bit fields
A bit field is an element of a structure that is defined in terms of bits. Using a special type of struct definition, you can declare a structure element that can range from 1 to 16 bits in length. It is useful
If the storage is limited you can store several Boolean variables in one byte Certain devices transmit information encoded into bits Certain encryptions routines need to access the bits within a byte.
struct student { int stno : 3; int age : 4; int gen : 1; } bit_var; Restrictions : Address of bit field cant be taken Bit field variables cant arrayed Any code used bit-fields machine dependencies
Files
Need for a file using the console oriented IO operation two major problems 1) it is cumbersome and time consume to handle large volume of data through terminals. 2) the entire data is lost when either the computer is turned off ot the program is terminated.
File Function
FILE *fp,*fp1,.; FILE *fopen(name,mode) fclose(file_pointer);
Data Structures
It is the arrangement of information in memory lactations by which the accessing and processing of the data will become easy . Depending on how the data is stored in memory and retrieved from memory the data structured can be classified as Linear data structures non liner data structures
Stack
Stack can be defied as an ordered collection of items into which items can be added or deleted at one end only. Key words of stack Top Push Pop Stack Over Flow Stack Under Flow
Stack operations\
Stack initializations Pushing the elements into the stack Pop the elements from the stack Display
Queues
Queue is an ordered collection of items, The items may be Deleted from one end called front end one end of the queue The items may be inserted from another end called rear end of the queue The queues are two types linear Queue circler Queue
Queue operations
Initialize the queue Pushing the elements Pop the elements Display
Linked lists
Linked lists is a sequence of data elements in which each element in the sequence point to int successor These pointers provide the links that codes the list together Only the way to access an element in the middle of the list is to start at the beginning of the list,element by element until you reach the target element
TREES
DEFINATION :A tree is a non-linear data structure, in which items are arranged in sorted sequence. It is represented in hierarchical relationship existing among several data items. It has a special data item called root of a tree. The remaining data items are partitioned into number of mutual exclusive subsets, each of which is itself a tree. They called subtrees. KEY TERMS IN TREES :ROOT :- It is specially designed data item in a tree. It is the first in the hierarchical arrangement of data items. NODE :- Each data item in tree is called a node. It is the basic data structure in tree. It specifies the information and link. DEGREE OF A NODE :- It is number of subtrees of a node in a tree.
TERMINAL NODE:- A node with degree is called terminal or leaf node. NON-TERMINAL NODE:- A node whose degree is not zero called non terminal node. Non-terminal nodes are intermediate nodes in the traversing the tree from its root node to the terminal node. SIBLINGS :- The children nodes of a given parent node is called Siblings. LEVEL:- The tree leveled in such a way that the root is always zero. The immediate children are at level 1. And goon If a node is at level n, then its children will be at level n+1. EDGE :- Connecting line of two nodes. That is, the line drawn from one node to another node is called an edge. PATH:- It is sequence of consecutive edge from source node to destination node.
DEPTH :- It is depth of maximum level of any node in a tree. FOREST :- It is set of disjoint trees, if you remove its root node its became the forest.
BINARY TREE:A binary tree is finite set of data items which consists single item called root and two disjoint binary tree is called Left subtree & Right subtree. In a binary the maximum degree of any node is at most two. There may zero degree or one or two. STRICTLY BINARY TREE:- If every non terminal node in a binary consists of non empty left subtree and right subtree such a tree called strictly binary tree.
C Type Examples
int i; int *j, k; unsigned char *ch; float f[10]; char nextChar(int, char*); int a[3][5][10]; int *func1(float);
int (*func2)(void);