-->

Examples of Bit fields

examples of bit fields in c languages
Example:
If we want to use the personal information of an employee in a compressed form.
struct personal
{
unsigned sex: 1
unsigned age: 7
unsigned mstatus : 1
unsigned children : 3
} emp;
·         This defines a variable name emp with four fields.
·         The range of values each field could have are as follows:
·         Once bit fields are defined, they can be referenced just as any other structure-type data item would be referenced.
·         The following assignment statements are valid.
emp.sex=1;
emp.age=50;
sum=sum+emp.age;
printf("%od",emp.age);
·         It is possible to combine normal structure elements with bit field elements.
struct personal
{
char name[20]; // normal variable
struct add address; //structure variable
unsigned sex:1;
unsigned age:7;
}
Command line Arguments
·         Command line arguments are the values supplied to the command prompt at execution time.
·         We can give parameters to main() with the help of the command line arguments main (int argc, char * argv [])
·         argc refers to arguments count. It returns a value which is equal to total number of arguments passed through the main() .
·         argv refers to argument vector. It is a pointer to an array of character strings which contains values of arguments.

Example:
argv [0] - first string
argv [1] - second string
In general argv [0] is an executable file to run the program.

Related Posts

Subscribe Our Newsletter