Questions
Electric charge
it is found experimentally that the charges are of two types
1. Positive charge
2. Negative charge
Positively charged body means deficiency of electrons in the body and a negatively charged body means excess of electrons
How much greater is one micro coulomb compared to an electronic charge?
1013 times
Structures
It is a user defined data type which represents a collection of logically related data items.It can represent a group of different types of data under a common name.
Structure Definition
The syntax to define the structure is,
struct structure _tag
{
data_type variable 1;
data_type variable 2;
...................................
Data_type variable N;
};
Struct is the keyword to define a structure. Structure _tag(or structure _name) is an identifier and variable 1,variable 2,.....variable N are identifiers to represent the data items constituting the grouped data.
The members of a structure is also called structure elements.
eg., struct student
{
int age;
Char name [10];
float fee;
};
Here student is a structure name and age, name, fee are elements of structure
Variable Declaration and Memory allocation
A variable is required to refer to a group of data. Once we have defined a structure data type, variable is declared using the following syntax :
struct structure _tag var1, var2, ......., varN;
OR
structure _tag var1, var2, ......., varN;
Here var1, var2, ........, varN; are the structure variable.
eg., struct student personal, acdemic;
Variable declaration statement causes memory allocation as per the size of the data type. The size depends upon the definition of the structure. A structure variable can be declared along with the definition also.
eg., struct student
{
int age;
char name [10];
float fee;
} personal, academic ;
Note: There is a limitation in this type of definition cum declaration. If we want to declare variables, to define functions, or to specify arguments using this structure later in the program, it is not possible since there is no tag to refer.
Variable Declaration and Memory allocation
A variable is required to refer to a group of data. Once we have defined a structure data type, variable is declared using the following syntax:
struct structure _tag var1, var2, ........., varN;
OR
structure_tag var1, var2, ......., varN;
Here var1, var2, ........, varN, are the structure variable.
eg., struct student personal, academic;
Variable declaration statement causes memory allocation as per the size of the data type. The size depends upon the definition of the structure. A structure variable can be declared along with the definition also.
eg., struct student
{
int age;
char name [10];
float fee;
} personal, academic ;
Note:There is a limitation in this type of definition cum declaration. If we want to declare variables, to define functions, or to specify arguments using this structure later in the program, it is not possible since there is no tag to refer.
Variable Initialisation
During the declaration of variables, they can be assigned with some values. This is known as initialisation. Its syntax is,
structure _tag variable = {value1, value2, ..........., valueN};
eg., student s = {14, "Aryan", 500.00};
Accessing Elements of structure
The elements of a structure are accessed using the dot (.) Operator or period operator. The syntax for accessing elements is, structure_variable. element _name
eg., s.age;
s.name;
Nested Structure
An element of a structure may itself itself be another structure. Such a structure is known as nested structure. The concept of nesting enables the building of powerful data structures.
eg., struct dob
{
int d,m, y;
};
struct student
{
char name [10];
int age ;
dob date;
};
Difference between array and structure
Array
. It is a derived data type.
. A collection of same type of data.
. Elements of an array are referenced using the corresponding subscript.
. When an element of an array becomes another array, multi-dimensional array is formed.
. Array of structure is possible.
Structure
. It is a user-defined data type.
. A collection of different types of data.
. Elements of structure are reference using dot operator(.)
. When an element of an structure becomes another structure, nested structure is formed.
. Structure can contain arrays as elements.