Professional Documents
Culture Documents
3.Single-Dimension Arrays
The general form for declaring a single-dimension array is
type var_name[size];
int a[10]; // array ‘a’ has 10 elements of type int, we would write
double balance[100]; // a 100-element array called balance of type double
balance[3] = 12.23; //assigns element number 3 in balance array the value
A variable that is a pointer to a pointer must be declared as such. This is done by 12.23
placing an additional asterisk in front of its name. For example, following is the char name[10]; // name is the character array variable that can hold a
declaration to declare a pointer to a pointer of type int – maximum of 10 characters
2.Build a C program to add 2 numbers using pointers. Structure is another user defined data type available in C that allows to combine data
items of different kinds. Structures are used to represent a record
#include <stdio.h>
int main() struct employee
{ {
int first, second, *p, *q, sum; char name[30];
printf("Enter two integers to add\n"); int empId;
scanf("%d%d", &first, &second);
float salary;
p = &first;
q = &second; long int adar number;
sum = *p + *q;
printf("Sum of the numbers = %d\n", sum); };
return 0; struct employee emp1, exp2,
}
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
3 4
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Benefits
1. Pointers can be used to return multiple values from a function via function
arguments.
2. pointers permit references to functions and thereby facilitating passing of
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ functions via function arguments.
6. Distinguish structure and union. 3. the use of pointer arrays to character strings results in saving of data storage
space in Memory.
4.They allow C to support dynamic memory management. They provide an
Key Structure Union
efficient tool for manipulating dynamic data structures such as structures , linked lists
Separate memory location Memory is allocated , queues , stacks and trees.
allotted for each input only to one member
Internal @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
member. having largest size
implementation
among all other input
variables.
size of a Structure is equal or Size or equal to the size
greater than the sum of size of largest member
Size
of all the data members. among all data
members.
5 6
8.Outline bit-fields with an example. 10..What is meant by stdin, sdtout and stderr.
Bit fields can be used to reduce memory consumption when a program requires a
number of integer variables which always will have low values: Pointer Stream
12.What is meant by lseek command. 14.What is meant by file descriptors in Unix OS.
A file descriptor is a unique identifier or reference that the operating system
lseek() system call repositions the read/write file offset i.e., it changes the positions
assigns to a file when it is opened.
of the read/write pointer within the file. In every file any read or write operations It allows programs to interact with files, sockets, or other input/output (I/O)
happen at the position pointed to by the pointer. lseek() system call helps us to resources.
manage the position of this pointer within a file. The file descriptor is used by the operating system to keep track of the file and
perform operations on it.
Examples: File descriptors are typically represented as non-negative integers.
lseek(fd,5,SEEK_SET) – this moves the pointer 5 positions ahead starting from the
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
beginning of the file
lseek(fd,5,SEEK_CUR) – this moves the pointer 5 positions ahead from the current
position in the file 15.Working with files
lseek(fd,-5,SEEK_CUR) – this moves the pointer 5 positions back from the current When working with files, you need to declare a pointer of type file. This
position in the file declaration is needed for communication between the file and the program.
lseek(fd,-5,SEEK_END) -> this moves the pointer 5 positions back from the end of
the file FILE *fptr;
Opening a file - for creation and edit
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ Opening a file is performed using the fopen() function defined in the
stdio.h header file.
13.Name some significant features of UNIX operating system.
1.Multi-tasking: More than one program can be run at a time The syntax for opening a file in standard I/O is:
2. Portability: The system is written in high-level language making it easier to ptr = fopen("fileopen","mode");
read, understand, changed and, therefore move to other machines.
3. Machine-independence: The System hides the machine architecture from @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
the user, making it easier to write applications that can run on any system.
4. Multi-User Operations: UNIX is a multi-user system designed to support a
group of users simultaneously.
5. Hierarchical File System: UNIX uses a hierarchical file structure to store
information. It allows for easy maintenance and efficient implementation.
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
9
PART- B
1. Explain why functions are needed? With syntax, illustrate how functions are declared and
defined? Categorize the 4 types of functions with example programs.
2. Interpret the significance of storage classes. List out them. Discuss their syntax. Classify the 4
types of storage classes with example programs.
3. (a) Mention the significance of pointers to functions. Demonstrate with an example program.
(function pointers)
(b) Explain how pointers are passed as arguments to a function. (call by reference)
(c) Discuss about arrays and pointers.
4.Declare and discuss various ways of initializing single, two and multi-dimensional arrays with
examples. How to multiply two 2D arrays. Write a program to multiply two 2D matrices. Analyse
with neat diagrams row-major and column major order storage of 2D arrays and demonstrate how
memory locations are identified in both.
5. Define structure. Explain its syntax and initialization. Write a program to demonstrate array of
structures to display the student database contains the following fields : rollno, name, branch and
fees. Explain how structures are accessed using pointers. Create a structure and show how it is
accessed via pointers.
6. Interpret the syntax of typedef and mention its significance. Using typedef explain how structure
variables are created and accessed. List out the advantages of variable length argument list. Design
a C program to demonstrate it.
7. Discuss in detail the standard I/O operations and Formatted I/O operations with example
programs. List out any 4 file modes and explain them.
8.Discuss error handling routines found in C with example programs. Explain about fopen() and
fclose () operations with programs.
9. Interpret the syntax of typedef and mention its significance. Using typedef explain how structure
variables are created and accessed. List out the advantages of variable length argument list. Design
a C program to demonstrate it.
10. Explain low level I/O operations handled by Unix OS and Elaborate the operations on files
- open, create, close, and unlink.