You are on page 1of 5

UNIT IV ( POINTERS AND DYNAMIC MEMORY ALLOCATION )

Write short notes on pointers? Write a program and explain working of malloc() , calloc() and free() function?
Pointer is a variable which is used to store address of another variable. Syntax : <datatype> *<pointername> ; Example : int *p; Is address a signed value or unsigned value? How much memory will be allocated to a pointer? Can we perform arithmetic operations on pointers? Will a pointer store address of a variable of same type or different type? Is there a pointer to store address of a variable of any datatype? What are the advantages with pointers? Dynamic memory allocation information. Syntax of malloc(), calloc() and free() functions with an example. What is the difference between malloc() and calloc()

Explain the syntax with suitable examples the dynamic memory allocation functions available in C.
What is Dynamic memory allocation? What are the functions for allocating memory dynamically? [ malloc(), calloc() and realloc() ] Specify the syntax of those functions along with an example. Specify the difference between malloc() and calloc().

What is a pointer? Give an example on call by Address?


Pointer is a variable which is used to store address of another variable. Syntax : <datatype> *<pointername> ; Example : int *p; Is address a signed value or unsigned value? How much memory will be allocated to a pointer? Can we perform arithmetic operations on pointers? Will a pointer store address of a variable of same type or different type? Is there a pointer to store address of a variable of any datatype? What are the advantages with pointers? What is the difference between call-by-value, call-by-reference and call-by-address? Give examples

UNIT V ( STRUCTURES UNIONS ENUMERATIONS BIT OPERATIONS )

Write a c program using structures to display the following information for each customer Customer name, accno , street, city, oldbalance ,currentpayment, newbalence, accstatus.
struct Account { char name[50],; int accno; char street[30]; char city[30]; int oldbalance; int currentpayment; int newbalance; char accstatus[30]; }; Declare an array of Account structure struct Account acc[100]; Read number of customers ( int n ) Read array of Accounts Print array of Accounts

List the differences between structures and unions


Definition Syntax Keyword Memory Allocation Application/Use

Structures -------------------------------

Unions ----------------

How to copy one structure to another structure of a same data type? give an example?
struct Student { int rno,marks; char name[25]; float per; }; Declare two variables of struct Student struct Student s1,s2; Read data into s1 Copy individual members from s1 to s2 s2.rno = s1.rno strcpy(s2.name,s1.name) s2.marks = s1.marks s2.per = s1.per

Write short notes on union with example?


Difference between structure and union Need for Union Syntax of Union Define a Sample Union and write example

Suppose or Oppose the statement in C a structure contains a union inside it? Give suitable example?
A structure can have definition of another structure or union within that. Write example by defining the same struct Student { int char float union { }L1; }; Declare a variable, draw memory allocation and write code struct Student { int char float struct { }d1; }; Declare a variable, draw memory allocation and write code

rno,marks; name[25]; per; Language int telugu,sanskrit,hindi;

rno,marks; name[25]; per; Language int telugu,Sanskrit,hindi;

Differentiate between self referential and nested structures with suitable examples?
A structure containing pointer to same structure is referred as Self-Referential structure. A structure defined in the definition of another structure is referred as Nested Structure. struct Student struct Student Nested structure { { int rno,marks; int rno,marks; Self Referential char name[25]; char name[25]; float per; float per; Write Code struct Student *p1; struct Dateofbirth }; { with comments int dd,mm,yy; }d1; };

In how many possible ways one can access the members of a structure using structure variable and a pointer to a structure variable. Illustrate with examples?
When we have a structure variable we can directly access the members of that structure variable using Member Access Operator/Dot Operator, represented with the symbol Dot(.) When we have pointer to a structure containing address of a structure variable, then we can access the members of that structure variable with the pointer using an operator called Indirection Operator, represented with the symbol -> struct Student { int rno,marks; char name[25]; float per; }; struct Student { int rno,marks; char name[25]; float per; }; struct Student struct Student p = &s1 ; s1 ; s1 . rno s1 . name s1 . marks s1 . per s1 ,*p; p p p p -> rno -> name -> marks -> per Directly structure variable Write code

Using Pointer Write code

Differentiate between array of structures and structure containing arrays with suitable examples?
struct Student { int rno,marks; char name[25]; float per; }; struct Student { int rno,marks; char name[25]; float per; }; struct Student s[10]; array of structures

rno marks name per

rno marks name per

rno marks name per

rno marks name per

0
struct Student s;

..

structure containing array

rno marks name per

How can entire structure be passed to a function explain with suitable examples?
struct Student { int rno,marks; char name[25]; float per; }; struct Student s1 = { 10,233,ABCD,44.56}; printstudent ( s1 ) ; Write program using this mechanism

Describe structure declaration, initilization and accessing elements?


Define a structure Syntax for defining a structure Example Memory allocation for a structure variable Declaring a structure variable Initializing a structure variable Accessing the members using Member Access Operator struct Student { int char float }; struct Student

rno,marks; name[25]; per; s1 = { 10,233,ABCD,44.56};

What is nested structure write a program to print the details of employees of an organization like name, date of joining, salary using nested structure?
The structure defined in another structure is referred as Nested Structure struct Employee { char name[25]; int sal; struct DateOfJoining { int dd ,mm, yy; } d1 ; }; Define structure like this Write program

Discuss the difference between structure and arrays?


Array is a collection of elements of same datatype. Structure is a collection of elements of same or different datatypes. Write Syntax, example, initialization etc

Write syntax for defining nested structure?


A structure defined in another structure is defined as Nested Structure. Syntax: struct <structure-name> { Declaring variables. .. .. struct <structure-name> { Declaring variables. .. } [ structure variables ] ; .. .. } [ structure variables ] ;

Example: struct Employee { char name[25]; int sal; struct DateOfJoining { int dd ,mm, yy; } d1 ; };

For the nested structure variable should be declared along with structure definition. Draw memory allocation and mention accessing of elements

What is an enumerated type? How it can be declared? What are the different ways one can initialize enumeration?
Enumeration is useful to declare a set of integer constants. Write syntax, example, initialization, declaring variables Syntax: enum Identifier { Enumerator list }; Example: enum Branch { Civil, Eee, Me, Ece, Cse }; Declaration Enum Branch b1 = Ece;

What do you mean by bit fields? How they are different from structures?
Bit fields allow packing of data in a structure. This is useful when memory or data storage should not be wasted. Only n lower bits will be assigned to an n bit number. So, type cannot take values larger than its size. Bit fields are always converted to integer type for computation. The unsigned definition is important and ensures that no bits are used as + flag. Syntax: struct <structure-name> { <type> <var-name> : width ; .. .. }; Example: struct Example { int x:2; int y:1; };

You might also like