Monday 30 April 2012

Bit Field


In addition to declarators for members of a structure or union, a structure declarator can also be a specified number of bits, called a "bit field." Its length is set off from the declarator for the field name by a colon. A bit field is interpreted as an integral type.
Although languages such as C or C++ have built-in support for bit fields, these can be still implemented manually, even in languages lacking native bit field native bitfield support. It suffices to have a set of integer constants, to which each a power of two is assigned, that semantically associates each individual bit with its respective semantic state.
struct-declarator:
declarator
type-specifier declarator opt constant-expression
The constant-expression specifies the width of the field in bits. The type-specifier for the declarator must be unsigned intsigned int, or int, and the constant-expression must be a nonnegative integer value. If the value is zero, the declaration has no declarator.


You may like the following posts:
User Defined Data types:

         Enum or Enumerations

Thursday 5 April 2012

3 rd Unit Test Papers


Third unit test
Set-1
Section a
1.       Define function? Explain the use of return statement?
Ans:
The return statement is used for two purposed, they are:
·         To return a value to the calling function.
Syntax: return(expression);
Ex: 1)return(c); //returning a variable
      2) return(x+y); //returning the expression ie.addition of variables x +y
To return the control back to the calling the function
Syntax: return;

1.       A return statement can appear any where in the function
2.       A function can have no of return statements in the function but one return statement  can be executed
3.       A return statement can return only one value at a time
2.       Write any difference b/w address & dereferencing operators?
3.       What is structure explain with an example?
Section b
4.       Explain various types of function with example programs?
5.       Explain about various dynamic memory management functions?
6.       What is recursion? Write a program to find the factorial of a given number using recursion?
                                               Set-2
1.       Distinguish between actual and formal parameters?
Ans:

     Actual parameters
      Formal parameters
     1.       The parameters specified in the function call are called as actual parameters
     The parameters specified in the function declaration are called formal parameters
    2.       Sending the value or variable or expression from the function call
Receiving the value or variable from the actual parameters
    3.       Ex: swap(a,b); or swap(2,3);
     Here a,b or 2,3 are actual parameters
Ex: void swap(int a, int b)
      {
      }
Here a,b are formal parameters
     4.       Passing the parameters a,b to swap()
Here a,b are receiving the value or variables
     5.       Actual parameters may be variable,value or expression, or structure,address
It must be variable or structure or array but not values or expressions
2.       What is pointer? List the advantages of pointers

Ans:
1.       We can return more than one value from a function
2.       Indirect accessing
3.       It provides dynamic memory management
4.       To pass arrays and strings more conveniently from one function to another function
5.       It provides program execution speed
6.       To manipulate arrays more easily by moving pointers to them instead of moving the arrays themselves
3.       Differentiate between array & structure?
Ans:

      Structure                                             
      Array
1.       It is a collection of elements(variables) of different data types
     1.       It is a collection of elements of same data type
2.       We have to use .(dot) operator or -> (cap) operator for accessing
      2.       Subscript for accessing array elements
3.       Syntax:
struct  tag
{
  Datatype memeber1;
  Datatype member2;
  …….
};
     3.       Declaration of array:
     Datatype arrayname[size]={list of elements separated by comma};
4.       Example:
     struct  student
     {
     int rollno;
     char name[10];
     float avg;
      };
     struct student stud={01,”raj\0”,90.25};
     4.       int a[5]={1,2,3,4,5};
                                                                                               Section -b
4.       Explain call by value and call by reference with example programs?
5.       Explain about addressing and dereferencing operators
ans:
       Address operator       
     Dereferencing operators
1.       Address operator is &
      Ex: &a where a is a variable
     Dereferencing operator is *
     Example: *a where a is pointer
2.       It is used to initialize pointer variable

      It is used to declare a pointer varialbe

3.       It is a unary operator
      It is also unary operator
4.       It returns the address of variable 
      It returns the value at that address


6.       What are the various storage classes in c explain?
                                Set-3
1.       What is self referential structure?
2.       List various betwise operators in c?
3.       List various I/O function with files?
                                Section-B
4.       Explain various types of functions with example with example programs
5.       Explain about various dynamic memory management functions with examples?
6.       What is recursion? Write a c program to find factorial of a given number using recursion?