You are on page 1of 31

UNIT I C PROGRAMMING BASICS

PART- A
1. Write down the steps involved in writing a program to solve a problem.
To design a program, a programmer must determine three basic steps:
a. The instruction to be performed.
b. The sequence in which those instructions are to be performed.
c. The data required to perform those instructions.

2. List out the various stages in evolution of C.


The various stages in evolution of C are as follows
Language Year Founder
ALGOL 1960 International group
BCPL 1967 Martin Richards
B 1970 Ken Thompson
C 1972 Dennis Ritchie
K & RC 1978 Kernighan and Ritchie
ANSIC 1989 ANSI Committee
ANSI/ISO C 1990 ISO Committee

3. What is the use of main ( ) function in C program? (May 2009)


Every C program must have main () function. All functions in C, has to begin with (and end
with) parenthesis. It is a starting point of all C programs. The program execution starts from
the opening brace {and ends with closing brace} within which executable part of the program
exists.

4. List the delimiters in


C. The delimiters in C are
a. : Colon
b. ; Semicolon
c. ( ) Parenthesis
d. [ ] Square Bracket
e. { } Curly Brace
f. # Hash
g. , Comma

5. What is the purpose of main( ) in C?


main ( ) is a special function used by the C system to tell the computer where the program
starts. Every program must have exactly one main function. The empty parenthesis
immediately following main indicates that the function main has no arguments.
6. Write any four escape sequences in C. (Jan
2013) Following are the escape sequences in C
a. \n -new line
b. \t –tab
c. \a –alert
d. \0 –null

1
7. What you mean by C tokensw? w(Jwun.Ae
C 20
tokens
1e2)are the basic buildings blocks in C language which are constructed together to write
U N wsBlog.net
a C program. Each and every smallest individual unit in a C program are known as C tokens.
„C‟ language contains the individual units called C tokens. C tokens are of six types. They
are as follows
a. Keywords (Ex: int, while)
b. Identifiers (Ex: main, total)
c. Constants (Ex: 10, 20)
d. Strings (Ex: “total”, “hello”)
e. Special symbols (Ex: (), {})
f. Operators (Ex: +, /,-,*)

8. What is a variable? Illustrate with an example. (Nov 2014)


A variable is an entity whose value can vary during the execution of a program. A variable
can be assigned different data items that at various places within the program. A variable is a
data name used for storing a data value. It can be assigned different values at different times
during program execution. Ex: a=3, b=5.

9. What are the different data types available in C? (June 2014)


Basic /Primitive Data Types Derived Data Types
Integer types (signed int, unsigned Arrays
int) Floating Type (float, double) Pointers
Character types (signed char) Structures, Enumeration

User Defined Data Types Void


Structure, Union

10. What is meant by Enumerated data type?


Enumerated data type is a user defined data type in C language. Enumerated data type
variables can only assume values which have been previously declared.
Ex. enum month { jan = 1, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec};

11. What are Keywords? What is the importance of keywords in C? (May 2015)
Keywords are pre-defined / reserved words in a C compiler. Each keyword is meant to can be
used only for a specific function in a C program. Since keywords are referred names for
compiler, they can‟t be used as variable name. Ex. auto, break, const, else

12. Define Constants in C. Mention the types.


The constants refer to fixed values that the program may not alter during its execution. These
fixed values are also called literals. Constants can be of any of the basic data types like an
integer constant, a floating constant, a character constant, or a string constant. Ex. const int
LENGTH = 10

www.AUNewsBlog.net 2
13. Difference between Local anwdwGwlo.bAaUl
vaerwiasbBle Local Variable Global Variable
N loing.Cn.et
a. Variables are declared inside a function. a. Variables are declared outside any
b. They are accessed only by the function.
statements, inside a function in which b. They are accessed by any statement in the
they are declared. entire program.
c. Local variables are stored on the stack, c. Stored on a fixed location decided by a
unless specified. compiler.
d. Created when the function block is d. Remain in existence for the entire time
entered and destroyed upon exit. your program is executing.
e. They are unknown to other functions e. They are implemented by associating
and to the main program. memory locations with variable names.
f. They are recreated each time a function f. They do not get recreated if the function
is executed or called. is recalled

14. What is different between a constant and variable? (Jan 2010)


Variable Constant
a. A variable is a space reserved in the a. A constant is value stored in the
machine memory for storing values in application code itself and is not stored in
runtime. the memory
b. The stored value can be changed anytime. b. The value of a constant cannot be
c. Variables are comparatively slow when changed.
compared to constants c. Constants are slightly faster than
variables because constants are stored in
the code not running the memory.

15. Is ‘main’ a keyword in C language? Justify your answer. (May 2011)


The name main is not a keyword in C. From the compiler's perspective, main() is a function.
Just like any other function that you may define in your program, such as factorial(), sort().
The simplest way to prove is that you can create a variable "main" in the program and that
will work.
#include <stdio.h> Output
int main()
{ The value of main is: 10
int main = 10;
printf("The value of main is: %d \n", main);
}

16. List out the rules to be followed in forming in identifier. (June 2010)
a. First letter should be alphabets.
b. Both numeric and alphabets are permitted.
c. Both lower case and upper case are allowed.
d. No special symbols are permitted except underscore ( _ ).
e. Keywords are not permitted, blank space is not allowed.

17. What is identifier? Give any two examples for an identifier. (Jan 2009)
Identifiers are the names given to variable program elements such as variables, functions and
arrays. Ex. STDNAME, sub, TOT_MARKS,sub123

www.AUNewsBlog.net 3
18. What are Operators? Menwtwiown .AthUeiNr etwypseBs loing.nCe. t What are
operators?
various types (Jan
of C 2014)
An operator is a symbol that tells the compiler to perform specific mathematical or logical
manipulations. C language is rich in built-in operators and provides following type of
operators
a. Arithmetic Operators d. Bitwise Operators
b. Relational Operators e. Assignment Operators
c. Logical Operators f. Misc Operators

19. What is the difference between ++a and a++?


++a means do the increment before the operation (pre increment) a++ means do the
increment after the operation (post increment).

20. Give two examples for logical and relational expression. (Jan 2011)
Relational Expression Logical Expression
(a>b) if((a>b)&&(a>c))
(a==b) if((a>b)||(a>c))

21. What are the Bitwise Operators available in C? (Jan 2011)


It is used to manipulate the data at bit level. It operates only integers.
Operator Meaning
& Bitwise AND
! Bitwise OR
^ Bitwise XOR
<< Shift Left
>> Shift Right
~ One‟s complement

22. Write the following conditions using ternary operator. (Jan 2009)


4x+100 for x<40
Salary= 300 for x=40
Salary= x<40?4*x+100:x>40?4.5*x+150:300;

23. What is type casting?


Type casting is a way to convert a variable from one data type to another data type. For
example, if you want to store a long value into a simple integer then you can typecast long to
int. You can convert values from one type to another explicitly using the cast operator.
int x,y;
c = (float) x/y;
where x and y are defined as integers. Then the result of x/y is converted into float.

24. What do you meant by conditional or ternary operator? Give an example for
Ternary operator. (Nov 2014)
Conditional or ternary operator‟s returns one value if condition is true and returns another
value is condition is false. Using ?: reduce the number of line codes and improve the
performance of application.
Syntax: (Condition? true_value: false_value); Ex: a<b ? printf("a is less") : printf("a is greater");

4
www.AUNewsBlog.net
25. What is the use of sizeof() opwewrawto.rAiUn NCe?wsBlog.net
sizeof() is used with the data types such as int, float, char… it simply return amount of
memory is allocated to that data types.
sizeof(char); //1
sizeof(int); //4
sizeof(float); //4
sizeof(double); //8
sizeof() is used with the expression, it returns size of the expression.
int a = 0;
double d = 10.21;
printf("%d", sizeof(a+d)); //8

26. Mention the various decisions making statement available in C.


a. if statement
b. if...else statement
c. nested if statements
d. switch statement
e. nested switch statements

27. What is the difference between if and while statement?


If While
a. It is a conditional statement. a. It is a loop control statement.
b. If the condition is true, it executes b. Executes the statements within the while
some statements. block if the condition is true.
c. If the condition is false then it stops c. If the condition is false the control is
the execution the statements. transferred to the next statement of the loop.

28. What are the types of looping statements available in C?


C programming language provides following types of loop to handle looping requirements.
a. for loop
b. while loop
c. do...while loop

29. Distinguish between while and do..while statement in C. (Jan 2009)


While Do..while
a. Executes the statements within the while a. Executes the statements within the while
block, if only the condition is true. block at least once.
b. The condition is checked at the starting b. The condition is checked at the end of
of the loop. the loop.
c. It is an entry controlled loop. c. It is an exit controlled loop.

30. Write a for loop statement to print numbers from 10 to 1. (Jan 2014)
#include <stdio.h>
void main(void) Output:
{ 10 9 8 7 6 5 4 3 2 1
int count; // Display the numbers 10 to 1
for(count = 10; count >= 1; count--) Press any key to continue . . .
printf("%d ", count);
}

www.AUNewsBlog.net 5
31. What are the types of I/O stawtwemwe.nAtUs
aNveaiwlasbBleloing.Cn?et
a. Formatted I/O Statements
b. Unformatted I/O Statements.

32. Differentiate between formatted and unformatted functions.


Formatted I/O functions Unformatted I/O functions
a. Formatted data requires more space a. Unformatted input/output is usually the
than unformatted to represent the same most compact way to store data.
information. b. Unformatted input/output is the least
b. Formatted input/output is very portable. portable form of input/output.
c. It is a simple process to move formatted c. Unformatted data files can only be moved
data files to various computers, even easily to and from computers that
computers running different operating share
systems, as long as they all use the ASCII the same internal data representation.
character set.

33. List the various input and output statements in C. (May


2015) The various input and output statements in C are
Input Statements Output Statements
a. gets() a. puts()
b. getch() b. putch()
c. getchar() c. putchar()
d. scanf() d. printf()
e. getche()

34. Write the limitations of using getchar() and scanf() functions for reading strings.
(Jan 2009)
getchar(): It is written in standard I/O library. It reads a single character only from a standard
input device. This function is not use for reading strings.
Scanf: It is use for reading single string at a time. When there is a blank was typed, the
scanf() assumes that it is an end.

35. What are the pre-processor directives? (Jan 2014, May 2014, 2015)
Preprocessor directives are the commands used in preprocessor and they begin with “#”
symbol. Before a C program is compiled in a compiler, source code is processed by a
program called preprocessor. This process is called preprocessing.
Syntax: #define
Macro
This macro defines constant value and can be any of the basic data types.
Syntax: #include <file_name>
Header file
The source code of the file “file_name” is included in the main program at
inclusion
the specified place.
Syntax: #ifdef, #endif, #if, #else, #ifndef
Conditional
Set of commands are included or excluded in source program before
compilation
compilation with respect to the condition.
Syntax: #undef, #pragma
Unconditional
#undef is used to undefine a defined macro variable. #Pragma is used to call
compilation
a function before and after main function in a C program.

www.AUNewsBlog.net 6
36. What are storage classes? www.AUNewsBlog.net
A storage class is the one that defines the scope (visibility) and life time of variables and/or
functions within a C Program.

37. What are the storage classes available in C?


Storage classes are categorized in four types as,
Automatic Storage Class - auto
Register Storage Class - register
Static Storage Class - static
External Storage Class - extern

38. What is register storage in storage class?


Register is used to define local variables that should be stored in a register instead of RAM.
This means that the variable has a maximum size equal to the register size (usually one word)
and can‟t have the unary '&' operator applied to it (as it does not have a memory location).
Ex. register int a=200;

39. What is static storage class? (Nov 2014)


Static is the default storage class for global variables. The static storage class object will be
stored in the main memory.
Ex. static int Count=19;

40. Define Auto storage class in C.


Auto is the default storage class for all local variables. The auto storage class data object will
be stored in the main memory. These objects will have automatic (local) lifetime.
Ex. auto int Month;

41. Define Macro in C. What is the use of #define preprocessor? (Nov 2014)
A macro can be defined as the facility provided by the C preprocessor by which a token can
be replaced by the user defined sequence of characters. Macros are defined with the help of
define directive. Its format is: #define identifier replacement.
#define TABLE_SIZE 100

42. What are conditional Inclusions in Preprocessor Directive?


The conditional inclusion directives are the one that is used to control the preprocessor with
conditional statements. Ex: #ifdef, #else, #endif

43. What you meant by Source file Inclusion in Preprocessor directive?


When the preprocessor finds an #include directive it replaces it by the entire content of the
specified file. There are two ways to specify a file to be included:
#include "filename.extension "
#include <filename.extension>

44. Define Compilation process.


Compilation process is defined as the processing of source code files and the creation of an
object' file. The compiler produces the machine language instructions that correspond to the
source code file that was compiled.
.

www.AUNewsBlog.net 7
45. What will be the output for wthwe wfo.lAloUwNinegwpsroBglroagm.n, ewthen
the (June 2012)
value of i is 5 and 10?
void main()
{
Output
int I; Five (if I is 5)
scanf(“%d”,&i); No output if I is 10
if(i=5)
{
printf(“five”);
}
}

PART - B
1. Explain different data types in C with examples.
2. What are the different operators available in C? Explain with examples.
3. Differentiate Signed and Unsigned integer.
4. Describe the statements for decision making, branching and looping.
5. Explain in detail about the formatted and unformatted I/O functions in C.
6. Discuss about bitwise operators and logical operators in C.
7. Explain any four format string with examples.
8. Write the syntax of „for‟ construct in C. Give an example.
9. Write the algorithm and C program to print the prime numbers less than 500.
10. Explain the following conditional
statements. Nested if-else statement
Switch-case statement
11. Write about the need and types of looping statements in C language and discuss
with examples. (Jan, Nov 2014, May 2015)
12. Write about the need and types of branching statements in C language and discuss
with examples. (Jan 2014)
13. Write a program to check whether a given number is prime or not. (May 2014)
14. Write a C program to find sum of digits of an integer. (May 2014)
15. Write a C program to find roots of a quadratic equation. (May 2014)
16. Differentiate entry and exit checked conditional constructs with an example. (May 2014)
17. What are the various operators available in C? Discuss each one of them with
suitable illustrations. (Nov 2014, May 2015)
18. What are constants? Explain the various types of constants in C. (May 2015)
19. Write a C program to solve any quadratic equations. (May 2015)

www.AUNewsBlog.net 8
UNITwIwI
wA.RARUAN YeSwAsNBDlogS.T
PART-
1. Def
ine array. Give example. (Jan 2009, 2014)
Array can be define as a collection of similar data elements of similar data type that are
stored in consecutive memory locations. They are referenced by an index/subscript.
Syntax: data_type array_name [size] Ex.: int rollno[10];

2. Why is it necessary to give the size of an array in an array declaration?


a. When an array is declared, the compiler allocates a base address and reserves enough
space in the memory for all the elements of the array.
b. The size is required to allocate the required space. Thus, the size must be mentioned.

3. What is the difference between an array and pointer?


Arrays Pointers

a. Array allocates space automatically. a. Pointer is explicitly assigned to point to an


allocated space.
b. It cannot be resized.
b. It can be resized using realloc().
c. It cannot be reassigned.
c. Pointers can be reassigned.
d. Sizeof (array name) gives the
number of bytes occupied by the d. Sizeof (pointer name) returns the number
array. of bytes used to store the pointer
variable.

4. List the characteristics of Arrays. (Jan 2013)


a. The elements of array share the same name and they are distinguished from one
another with helps of an elements number.
b. An elements of array a[] can be assigned
c. The array elements are stored in continuous memory locations.

5. What are the types of Arrays?


a. One-Dimensional Array
b. Two-Dimensional Array
c. Multi-Dimensional Array

6. Write the features of array. (Jan 2013)


a. An array is a derived data type. It is used to represent a correction of elements of the
same data type.
b. The elements can be accessed with base address and the subscript defined for the
position of elements.
c. The elements are stored in continuous memory location
d. The starting memory location is represented by the array name and it is known as the
base address of the array.

7. Define One dimensional Array.


One dimensional array can be defined as the collection of data item that can be stored under a
one variable name using only one subscript. Ex. int a[10];

www.AUNewsBlog.net
9
8. Define Two Dimensional
Two
Arrawdimensional arrays can be defined as an array with two subscripts. A two dimensional
yws. w.AUNewsBlog.net
array enables us to store multiple row of elements. Ex. int a[10][10];

9. Give example for array initialization.


An array can be initialized at the time of declaration is known as compile time
initialization. Ex. int a[5]={5,3,5,4,1};

10. Why do you need to use array? (Jan 2012)


In many cases, we need to declare a set of variables that are of the same data type. Instead of
declaring each variable separately, we can declare all variable collectively in the format of an
array. Each variable, as an element of the array, can be accessed either through the array
elements references or through a pointer that references the array.

11. List out the disadvantages of an array.


a. The elements in the array must be same data types.
b. The size of an array is fixed.
c. If we need more space at run time, it Is not possible to extend array.
d. The insertion and deletion an operation is an array require shifting of elements which
takes times.

12. What are the limitation of one-dimensional and two dimensional arrays?
The limitations of one dimensional array are
a. There is no easy method to initialize large number of array elements
b. It is difficult to initialize selected array element
The limitations of two dimensional arrays are
a. Deletion of any element from an array is not possible
b. Wastage of memory when it is specified in large array size

13. Why array elements must be initialized?


After declaration array elements must be initialized otherwise it holds garbage value. There
are two types of initialization
a. compile time initialization(initialization at the time of
declaration) int a[5]={12,34,23,56,12};
b. run time initialization (when the array has large number of elements it can be
initialized at run time)
for(i=0;i<10;i++)
scanf(“%d”,&a[i]);

14. What is the value of b in the following program?(Jan


2012) main()
{int a[5]={1,3,6,7,0}; Output: 6
int *b;
b=&a[2];
printf(“%d”,*b);
}

www.AUNewsBlog.net 10
15. Write a C program to calculwatwe
#include
wth.eAp<stdio.h>
UoNweewr osfBalongu.mnebter.
int main() Output
{
int base, exponent; Enter a base number: 3
long long result = 1; Enter an exponent: 4
printf("Enter a base number: "); Answer = 81
scanf("%d", &base);
printf("Enter an exponent: ");
scanf("%d", &exponent);
while (exponent != 0)
{
result *= base;
--exponent;
}
printf("Answer = %lld", result);
return 0;
}

16. Write a C program to generate Pascal triangle.


#include <stdio.h>
void main()
{
int array[30], temp[30], i, j, k, l, num; //using 2 arrays
printf("Enter the number of lines to be printed: ");
scanf("%d", &num);
temp[0] = 1;
array[0] = 1; Output
for (j = 0; j < num; j++) Enter the number of lines to be printed: 4
{ 1
printf(" "); 1 1
} 1 21
printf(" 1\n"); 1331
for (i = 1; i < num; i++)
{
for (j = 0; j < i; j++)
printf(" ");
for (k = 1; k < num; k++)
{
array[k] = temp[k - 1] + temp[k];
}
array[i] = 1;
for (l = 0; l <= i; l++)
{
printf("%3d", array[l]);
temp[l] = array[l];
}
printf("\n");
}
}

www.AUNewsBlog.net 11
17. Write a C program to find twhewnwu.mAbUeNr
array.
oefwes#include
leBmloen<stdio.h>
gt.sneint an
int main() Output
{
int array[] = {15, 50, 34, 20, 10, 79, 100}; Size of the given array is 7
int n;
n = sizeof(array);
printf("Size of the given array is %d\n",
n/sizeof(int)); return 0;
}

18. Define Strings.


Strings or character arrays can be defined as the group of characters, digit and symbols
enclosed within quotes. Strings are always terminated with “\0” (NULL) character. The
compiler automatically adds “\0” at the end of the strings.

19. What is the use of ‘\0’ character?


When declaring character arrays (strings), “\0” (NULL) character is automatically added at
end. The “\0‟ character acts as an end of character array.

20. Define string.h.


String.h is a header file which includes the declarations, functions, constants of string
handling utilities. Ex.: strlen(), strrev(), strncpy().

21. How strings are represented in C language?(Jan 2010)


Strings in C are represented by arrays of characters. The end of the string is marked with a
special character, the null character, which is simply the character with the value 0. (The null
character has no relation except in name to the null pointer. In the ASCII character set, the
null character is named NUL.) Ex.: char string1[] = "Hello, world!";

22. How strings are declared and initialized in C?


Strings are declared as a array of characters Syntax:
Initialization
char string_name[size];
of strings Char name[6]=”RAMKI”;
Example: char text[30]; Char city[]={„B‟,‟O‟,‟M‟,‟B‟,‟A‟,‟Y‟,‟\0‟};

23. Write important string handling functions in C.


Some of the important strings handling functions in C are as follows
a. strcat()-concatenates two strings
b. strcmp()-compares two strings
c. strcpy()-copies one string over other
d. strlen()-finds length of a string
e. strrev()-reverse the string

24. What is the difference between a string and an array?


String Array
a. String can hold only char data
a. Array can hold any data type
b. String size can be changed if it is a
b. Array size cannot be changed
character pointer
c. The last element of an array is an element
c. The last character of string is a null –
of the specific type
„\0‟character
d. The length of an array is specified in []
d. The length of the string is the number of
at the time of declaration (except char[])
characters + one

www.AUNewsBlog.net 12
25. Write a C program to inputwa wstwri.nAgUaNndewstsorBelothge.inreAt SCII
andinprint
values the array.
an integer array Output
#include <stdio.h>
void main() Enter the no of characters to be
{ in an array 8
char string[20]; Enter the string of 8
int n, count = 0; characters ProgRams
printf("Enter the no of characters to be in an array P = 80 r
\n"); scanf("%d", &n); = 114 o
printf(" Enter the string of %d characters \n" , n); = 111 g
scanf("%s", string); = 103 R
while (count < n) = 82 a
{ = 97 m
printf(" %c = %d\n", string[count], string[count]); =
++ count; 109 s =
} 115
}
26. What is the formula to calculate determinant of 3 x 3 Matrix?
a bc

A  d e f  | A | aei  fh bdi  gf  cdh  eg 
 
g h i
 
27. What is the use of strlen()?
This function is used to count and return the number of character present in a
string Syntax: len=strlen(string);

28. What is the use of strcat()?


This function is used to concatenate or combine to strings together then forms a new
string. Syntax: strcat(str1,str2);

29. What is the use of strrev()?


This function is used to reverse a string. This function takes and return only one
argument Syntax: strrev(str);

30. What is the use of strcmp()?


This function which compares two string to find whether they are same or different. If two
strings are equal means it return a zero otherwise numeric difference between the non
matching character
Syntax: strcmp(string1,string2);

31. What does strncpy()do?


strncpy()copies portion of one string to another string. Ex : strncpy(str1 , str2 ,4)
It copies first 4 characters of str2 to str1.

www.AUNewsBlog.net 13
32. Define sorting. www.AUNewsBlog.net
Sorting can be defined as a technique to rearrange the elements of a list in ascending or
descending order, which can be numerical, lexicographical, or any user-defined order. Sorting
is a process through which the data is arranged in ascending or descending order.

33. What are the two type of sorting techniques?


The two types of sorting are as follows
Internal sorting: If sorting operation is done in main memory of computer then it is called as
internal sorting Ex. bubble sort, selection sort, quick sort, radix sort, heap sort.
External sorting: If sorting operation is done in secondary memory of computer then it is
called as external sorting Ex. multi-way merge, polyphase merge.

34. Define searching.


Searching can be defined as the process by which one searches the group of elements for the
desired element. There are different methods of searching but let us deal two popular
methods of searching and they are linear search and binary search.

35. Mention the various types of searching techniques in C.


The various types of searching techniques in C are
a. Linear search
b. Binary search

PART-B
1. Discuss about any eight built in functions of string. (Jan 2013)
2. Briefly explain the various string handling functions in C. (Jan 2010)
3. Write C program to sort the given set of numbers in ascending order. (Jan 2013, 2011)
4. Write C program to find addition of two matrices. (Jan 2013, 2014)
5. Write C program to find multiplication of two matrices.
6. Write a C program to reverse a given string. (May 2011)
7. Write C program to perform scaling on a given matrix.
8. Write C program to calculate determinant of a matrix
9. Write a C program to convert the given string from lowercase characters to uppercase
character and uppercase to lowercase. (May 2011)
10. Write a C program using arrays with height of persons and find how many persons are above
the average height.
11. Populate a two dimensional array with height and weight of persons and compute the Body Mass
Index of the individuals.
12. Write a C program to find largest and smallest number in the given array. (May 2010)
13. Write a C program to concatenate two strings. (May 2009)
14. Write a C program to demonstrate one dimensional, two dimensional and
multidimensional arrays.

www.AUNewsBlog.net 14
UNIT IIwI
FwUwN.ACUTIPART-
NOeNwASsABNloDg.Pn
1. What is a function? (Nov 2014)
A function is a group of statements that together perform a task. Every C program has at least
one function which is main(), and all the most trivial programs can define additional
functions.

2. How will define a function in C?


The general form of a function definition in C programming language is as
follows return_type function_name (parameter list)
{
body of the function
}

3. What does a function header and function body consist of?


A function definition consists of The Function header consists of
a. Function header a. Return Type
b. Function body b. Function Name
c. Parameters
The Function body consists of
a. Declarations and statements necessary for performing the required task.

4. What are the steps in writing a function in a program?

a. Function Declaration/Prototype: Every user-defined functions has to be declared


before the main().
b. Function Callings: The user-defined functions can be called inside any functions like
main(), user-defined function.
c. Function Definition: The function definition block is used to define the user-defined
functions with statements.

5. What is the need for functions? (Jan 2014)


a. Functions are self-contained block or sub program of one or more statements that
performs a specific task.
b. It increases the modularity, reusability of a program.

6. What is the purpose of the main ()? (May 2009)


The main () invokes other functions within it. It is the first function to be called when the
program starts execution.

7. What are the elements of user-defined function?


a. Function Definition.
b. Function Declaration.
c. Function call

8. List the types of functions in C programming.


Depending on whether a function is defined by the user or already included in C compilers,
there are two types of functions in C programming
a. Standard library functions
b. User defined functions

15
www.AUNewsBlog.net
9. What are standard library fuwncwtiwon.sA?
The standard library functions are built-in functions in C programming to handle tasks such
UNewsBlog.net
as mathematical computations, I/O processing, string handling. These functions are defined in
the header file. When you include the header file, these functions are available for use. For
example: The printf() is a standard library function to send formatted output to the screen
(display output on the screen). This function is defined in "stdio.h" header file.

10. List the advantages of user-defined function. The


advantages of user defined functions are as follows
a. The program will be easier to understand, maintain and debug.
b. Reusable codes that can be used in other programs
c. A large program can be divided into smaller modules. A large project can be divided
among many programmers.

11. Is it better to use a macro or a function?


Macros are more efficient than function, because their corresponding code is inserted directly
at the point where the macro is called. There is no overhead involved in using a macro like
there is in placing a call to a function. Macros are generally small and cannot handle large,
complex coding constructs. In cases where large, complex constructs are to handled,
functions are more suited, additionally.

12. Classify the functions based on arguments and return values.


Depending on the arguments and return values, functions are classified into four types.
a. Function without arguments and return values.
b. Function with arguments but without return values.
c. Function without arguments but with return values.
d. Function with arguments and return values.

13. What are address operator and indirection operator? (Nov 2014)
a. The address operator (&) - It represents the address of the variable.
b. Indirection pointer (*) - When a pointer is dereferenced, the value stored at that
address by the pointer is retrieved.

14. What is function prototyping? Why it is necessary? (May 2011)


Many built in functions can be used in C programs. The prototype of these functions is given
in the respective header files. With the help of a function prototype, the compiler can
automatically perform type checking on the definition of the function, which saves the time
to delay the program.

15. What are actual parameters and formal parameters? (May 2015)
Actual Parameters: The parameters in the calling program or the parameters in the function
call are known as actual parameters.
Formal Parameters: The parameters in the called program or the parameters in the function
header are known as formal parameters.

16. State the advantage of using functions.


The advantages of using functions are as follows
a. Reduces the size of the program: The length of the source program can be reduced by
using functions at appropriate places.
b. Avoids rewriting the code: As function can be called many times in the program.
c. Improves re-usability: Same function may be used later by many other programs.

www.AUNewsBlog.net 16
d. Makes program developmwenwt wea.sAy:UWNoerwk scaBnlobge.dnievitde
implementation
among can be
project members completed in parallel.
thus
e. Program testing becomes easy: Each function can be tested separately and it is easy
to locate and isolate a faculty function for further investigation.
f. Increases program readability.

17. Differentiate library functions and User-defined functions.


Library Function User- defined functions
a. The library functions are predefined a. The user defined functions are defined by
set of functions. the user.
b. Their task is limited b. Their task is based on user requirement.
c. The user can use the functions but c. The user can modify the function
cannot change or modify them. according to the requirement.

18. What is a recursive function?


If a function calls itself again and again, then that function is called Recursive function. This
technique is known as recursion.
void recursion()
{ recursion(); /* function calls itself */
}
int main()
{ recursion(); }

19. What are the applications of recursive function?


The applications of the recursive function are
a. Calculating Fibonacci Series.
b. Calculating Factorial of a program.

20. State the advantage and disadvantage of recursive function.


Advantage of recursive function Disadvantage of recursive function
Reduce unnecessary calling of function. It is very difficult to trace (debug and understand)
Through recursion one can solve problem in easyTakes
way while
a lot ofitsstack
iterative
space.
solution is very big and complex.
Uses more processor time.

21. What is a Pointer? How a variable is declared to the pointer? (Jan 2013, May
2009) Pointer is a variable which holds the address of another variable.
Syntax: data_type *variable_name;
Ex.: int *x, a=5;
x=&a;

22. List the key points to remember about pointers in C.


The key points to remember about pointers in C are
a. The content of the C pointer always be a whole number i.e. address.
b. Always C pointer is initialized to null i.e., int *p=null.
c. The value of null pointer is 0.
d. The size of any pointer in 2 byte.

www.AUNewsBlog.net 17
23. What are the uses of Pointerws?w(wJa.An U20N1e4w,
The
MsBuses
ayloof
2gpointers
0.1n2e, tare
May as2010)
follows
a. Pointers are used to return more than one value to the function
b. Pointers are more efficient in handling the data in arrays ·Pointers reduce
the length and complexity of the program ·
c. They increase the execution speed
d. The pointers save data storage space in memory

24. What is dangling pointer?


In C, a pointer may be used to hold the address of dynamically allocated memory. After this
memory is freed with the free() function, the pointer itself will still contain the address of the
released block. This is referred to as a dangling pointer. Using the pointer in this state is a
serious programming error. Pointer should be assigned NULL after freeing memory to avoid
this bug.

25. What is the output of the following program? (May 2015)


main ()
{
Output
int a=8, b=4, c, *p1=&a, *p2=&b; c: 39
c=*p1**p2-*p1/ *p2+9;
printf (“%d”,c); }

26. List the pointer operators.


* Value at Operator Gives values stored at particular address
& Address Operator Gives address of variable

27. What is the output for the


following? #include<stdio.h> Output
int fun()
38353229262320171411852
{
static int num =
40; return num--;
}
int main()
{
for(fun(); fun(); fun())
{
printf("%d", fun());
}
getchar();
}
28. What is a pointer variable?
The variables that hold the memory address are called pointer variables.
int *p;
P = &n;
P stores the address of n.

www.AUNewsBlog.net 18
29. What will be output of the
#include<stdio.h>
fowllwow wi.nAgUpNroegwrasmB?log.net
int main() Output
{ 20
int n=20; 1260034844
printf(“\n %d “, n); 20
printf(“\n %u“, &n);
printf(“\n %d “, *(&n));
}

30. What are the possible arithmetic operations on pointers in C language?


a. Increment
b. Decrement
c. Subtraction
d. Comparison

31. What are null pointers?


A pointer that does not point to any valid memory address is called null
pointer. Ex: int * ptr =NULL;

32. List out the applications of pointers.


a. We can section multiple values from function using pointer.
b. Supports dynamic management.

33. What are pointers to pointers?


Pointer variable contains the address of another variable. Similarly another pointer variable
can store the address of a pointer variable. The pointer variable is said to be pointer to
pointer.

34. What is pointer arithmetic?


One of the uses of pointer is pointer arithmetic. Like an ordinary variable, pointer variable
can also be used in arithmetic expressions. Assume x, y and z are pointer variables, and the
values are 10, 20, 30 respectively. Then the following is an example of pointer expression.
Expression Result
C =*y + 10 Value of c is 30
C = *z + *y Value of c is 50
C = *x + 10 + *y Value of c is 40
C = ++*x Value of c is 11

35. Distinguish between Call by value Call by reference. (May 2014)


Call by Value / Pass by value Call by reference / Pass by reference
a. In Call by value, the value of actual a. In Call by reference, the address of
agreements is passed to the formal actual arguments values is passed to
arguments and the operation is done on formal argument values.
formal arguments. b. Formal arguments values are pointers
b. Formal arguments values are to the actual arguments values.
photocopies of actual arguments values. c. Since address is passed, the changes
c. Changes made in formal arguments valued made in the formal arguments will be
do not affect the actual argument values reflected back to the actual arguments.

19
www.AUNewsBlog.net
www.APUANReTw-
sBBlog.net
1. Explain in detail about Function with example.
2. Explain function with and without arguments with example for each. (Jan 2014)
3. What is recursion? Give an example and explain in detail. (Jan 2014, Nov 2014)
4. Explain (Jan 2014, May 2014, Nov 2014)
(i) Function declaration
(ii) Call by reference; call by value with an example.
5. Explain the use of pointers in arrays with suitable example. (May 2014)
6. How array elements are accessed using pointers?
7. How can you pass a array as a parameter in C? Give an example
8. How can you pass a pointer as a parameter in C? Give an example.
9. Write a function using pointers to add two matrices and to return the resultant matrix
to the calling function. (May 2012)
10. Write a C program to find the factorial of a given number using function. (May 2014)
11. Write a C program to exchange the values of two variables using pass by
reference. (May2014)
12. Write a C program to find the sum of the digits using recursive function. (May 2015)
13. Write a C program to using pointers to read in an array of integers and print its
elements in reverse order. (May 2015)
14. Write an iterative and recursive function to find the power of a number. (Nov 2014)
15. Explain any 5 string functions with example.
16. Explain the math functions briefly.
17. Explain in detail about recursion with an example.
18. Write a program to calculate the sine series using function recursion.
19. Explain pointer arithmetic with examples.
20. Explains the use of pointers in handling arrays.
21. Write a program to sort names using pointers.
22. With a suitable example explain the pass by reference method of calling a function.

UNIT IV STRUCTURES
PART – A
1. Distinguish between arrays and structures.
Arrays Structures
a. An array is a collection of data items of a. A structure is a collection of data items
same data type. Arrays can only be of different data types. Structures can be
declared. declared and defined.
b. There is no keyword for arrays b. The keyword for structures is struct.
c. An array name represents the address c. A structure name is known as tag. It is
of the starting element a Shorthand notation of the declaration.
d. An array cannot have bit fields d. A structure may contain bit fields

www.AUNewsBlog.net 20
2. Differentiate structures and log.net
uwniwonws..A(JUStructure
aNn e20w1s4B) Union
a. Every member has its own memory. a. All members use the same memory.
b. The keyword used is struct. b. The keyword used is union.
c. All members occupy separate memory c. Different interpretations for the same
location, hence different interpretations of memory location are possible.
the same memory location are not possible.
d. Consumes more space compared to union. d. Conservation of memory is possible.
3. Define Structure in C.
Structure can be defined as a collection of different data types which are grouped together
and each element in a C structure is called member. To access structure members in C,
structure variable should be declared. The keyword used is struct.

4. How will you define a structure?


A structure can be defined as
struct tag
{
datatype member 1;
datatype member 2;
………
………
datatype member n;
};
where struct is a keyword, tag is a name that identifies structures, member 1, member 2,…..
member n are individual member declarations.

5. How will you declare structure variables? struct library_books


Declaration of structure variables includes the following {
statements char title[20];
char author[15];
a. The keyword struct int pages;
b. The structure name float price;
};
c. List of variable names separated by commas
struct library_books b1,b2,b3;
d. A terminating semicolon

6. What is meant by Union in C? (May 2014)


A union is a special data type available in C that enables to store different data types in the
same memory location. Union can be defined with many members, but only one member can
contain a value at any given time. Unions provide an efficient way of using the same memory
location for multi-purpose.

7. How to define a union in C.


The format of the union statement is as follows
union tag
{
member definition;
member definition;
...
member definition;
} one or more union variables;

www.AUNewsBlog.net 21
8. How can you access the memwbwerws .oAf UthNe eUwnsioBnl?og.net
To access any member of a union, use the member access operator (.). The member access
operator is coded as a period between the union variable name and the union member to
access. Union keyword is used to define variables of union type.

9. List the features of structures. (May 2015)


The features of structures are as follows
a. All the elements of a structure are stored at contiguous memory locations
b. A variable of structure type can store multiple data items of different data types under
the one name

10. List the main aspects of working with structure.

a. Defining a structure type (Creating a new type).


b. Declaring variables and constants (objects) of the newly created type.
c. Initializing structure elements

11. What are the two ways of passing a structure to function in C?

a. Passing structure to a function by value


b. Passing structure to a function by address(reference)

12. Write any two advantage of Structure.

a. It is used to store different data types.


b. Each element can be accessed individually.

13. How to initialize a structure variable? Give it’s syntax.


Static storage class is used to initialize structure. It should being and end with curly braces.
Syntax: Static structure tag-field structure variable = {value1, value2,...value 3};

14. Define Anonymous structure.


Unnamed anonymous structure can be defined as the structure definition that does not contain
a structure name. Thus the variables of unnamed structure should be declared only at the time
of structure definition.

15. What are the operations on


structures? The operations on structures are
a. Aggregate operations: An aggregate operation treats an operand as an entity and
operates on the entire operand as whole instead of operating on its constituent
members.
b. Segregate operations: A segregate operation operates on the individual members of a
structure object.

16. How to access members of a structure object?

a. Direct member access operator (dot operator)


b. Indirect member access operator(arrow operator)

17. What is the use of ‘period (.)’ in C?


To access any member of a structure, we use the member access operator (.). The member
access operator is coded as a period between the structure variable name and the structure

22
www.AUNewsBlog.net
member that we wish to access. Pwerwiowd .iAs uUsNedetwo
sinBitlioagli.zneeatstructure. The members of structure can be accessed individually
18. How will you access the structures member through pointers?
The structures member can be accessed through pointers by the following ways
a. Referencing pointer to another address to access memory
b. Using dynamic memory allocation

19. Define Nested structure.


Nested structure can be defined as the structure within structure. One structure can be
declared inside other structure as we declare structure members inside a structure. The
structure variables can be a normal structure variable or a pointer variable to access the data.

20. Define array of structures.


Each elements of an array represent a structure variable. If we want to store more array
objects in a structure, then we can declare “array of structure”.

21. Consider the declaration and illustrate the application of size of operator to
this structure. (Nov 2010)
struct student
{ Size of this is 3 bytes:1 byte for name and 2 bytes for integer num.
char name;
int num;
} S;

22. Define Dynamic memory allocation.


The process of changing the array size during program execution is called as dynamic
memory allocation.

23. What are various dynamic memory allocation functions in C?


a. malloc() – Used to allocate blocks of memory I required size of bytes
b. free() – Used to release previously allocated memory space
c. calloc() –Used to allocate memory space for an array of elements
d. realloc()-Used to modify the size of previously allocated memory space

24. What is a volatile and non-volatile memory?


Volatile memory: also known as volatile storage is computer memory that requires power to
maintain the stored information, unlike non-volatile memory which does not require a
maintained power supply. It has been less popularly known as temporary memory. Non-
volatile memory: nonvolatile memory, NVM or non-volatile storage, is computer memory
that can retain the stored information even when not powered.

25. What is Linked List?


A linked list is a set of nodes where each node has two fields „data and „link‟. The data field
is used to store actual piece of information and link field is used to store address of next node.

26. Write down the steps to modify a node in linked


lists. The steps to modify a node in linked lists are
a. Enter the position of the node which is to be modified.
b. Enter the new value for the node to be modified.

www.AUNewsBlog.net 23
c. Search the corresponding
d. noReplace
w wdewi.nthe
AtU heNlein
original wkesofdBthat
value llionode
sgt. .net
by a new value.
e. Display the message as “The node is modified”.
27. List the operations on singly linked list.
a. Create function
b. Display function
c. Search function
d. Insert function
e. Delete function

28. What are the pitfalls encountered in singly linked list?


The singly linked list has only forward pointer and no backward link is provided. Hence the
traversing of the list is possible only in one direction. Backward traversing is not possible.
Insertion and Deletion operations are less efficient because for inserting the element at
desired position the list needs to be traversed. Similarly, traversing of the list is required for
locating the element which needs to be deleted.

29. Define doubly linked list.


Doubly linked list can be defined as a kind of linked list in which each node has two link
fields. One link field stores the address of previous node and the other link field stores the
address of next node.

30. Differentiate between arrays and lists


In arrays any element can be accessed randomly with the help of index of array, whereas in
lists any element can be accessed by sequential access only. Insertions and deletions of data is
difficult in arrays on the other hand insertion and deletion of data is easy in lists.

31. Write syntax of calloc() and relloc().


Calloc() is for allocating the required amount of memory.
Syntax: Void *calloc(size_t nitems,size_t size)
Relloc() function modifies allocated memory size by malloc() and calloc().
Syntax:Void *relloc(void *ptr,size_t size)

32. What is the use of typedef?


Typedef is used for renaming data types. It redefines the name of existing variable type. It
provides a short and meaningful way to call a data type.

PART - B
1. Define Structures. Explain structures in detail.
2. Explain array of structure in C.
3. Write a C program to create mark sheet for students using structure. (Jan 2014)
4. How can you insert structure with in another structure?
5. Explain the concept of structures and functions, structures and pointers with example.

www.AUNewsBlog.net 24
6. Define Union. Explain Union inwdwewta.iAl.
U(M
7. Naeare
What ywstorage
2s0B15classes?
lo) g.netExplain each with example. (May 2014, Jan 2014, May 2015)
8. Describe in detail about the Preprocessors in C.
9. What is a structure? Create a structure with data members of various types and declare two
structure variables. Write a program to read data into these and print the same. (Nov 2014)
10. Justify the need for structured data type. (Nov 2014)
11. Write notes on: (Nov 2014)
(i) Unions
(ii) Register storage class
(iii) #include statement
(iv) #ifndef…#endif
12. Define a structure called book with book name, author name and price. Write a C
program to read the details of book name, author name and price of 200 books in a library and
display the total cost of the books and the book details whose price is above Rs. 500. (May
2015)
13. Write a C program using structure to store date, which includes day, month and year. (Jan
2014)
14. Write a C program to store the employee information using structure and search a
particular employee using Employee Number. (June 2014)
15. A sample C programming code for real time Bank application program is given below.
This program will perform all below operations.
(i) Creating new account: To create a new account
(ii) Cash Deposit: To Deposit some amount in newly created account
(iii)Cash withdrawal: To Withdraw some amount from your account
(iv) Display Account information: It will display all information‟s of the existing accounts
(v) Log out
(vi) Clearing the output screen and display available options

UNIT V FILE PROCESSING


PART-A
1. What is a file?
A file is a collection of related data stored on a secondary storage device like hard disk. Every
file contains data that is organized in hierarchy as fields, records, and databases. Stored as
sequence of bytes logically contiguous (may not be physically contiguous on disk).

2. List out the types of files. The


following are the types of files
a. Text file or ASCII text file: collection of information or data which are easily
readable by humans. Ex. .txt, .doc, .ppt, .c, .cpp
b. Binary file: It is collection of bytes. Very tough to read by humans. Ex. .gif, .bmp,
.jpeg, .exe, .obj

www.AUNewsBlog.net
6. Define Union. Explain Union inwdwewta.iAl.
U(MNaeyw2s0B15lo) g.net
25

www.AUNewsBlog.net
3. What are the standards
strewamwswa.vAaUilaNbelewisnBCloLga.nngeut age?
a. Standards input(stdin)
b. Standards output(stdout)
c. Standards error(stderr)

4. What are file attributes?

a. File name
b. File Position
c. File Structure
d. File Access Methods
e. Attributes flag

5. What is the use of functions fseek(), fread(), fwrite() and ftell()?


a. fseek(f,1,i)Move the pointer for file f of a distance 1 byte from location i.
b. fread(s,i1,i2,f)Enter i2 dataitems, each of size i1 bytes from file f to string s.
c. fwrite(s,i1,i2,f)send i2 data items,each of size i1 bytes from string s to file f.
d. ftell(f)Return the current pointer position within file f.
e. The data type returned for functions fread,fseek and fwrite is int and ftell is long int.

6. How is a file opened and file closed?


a. A file is opened using fopen()function. Ex: fp=fopen(filename,mode);
b. A file closed using fclose()function. Ex: fclose(fp);

7. What are the statements used for reading a file? (Nov 2014)
a. FILE*p;Initialize file pointer.
b. fp=fopen(“File_name” ”r”);Open text file for reading.
c. Getc(file_pointer_name);Reads character from file.
d. fgets(str,length,fp); Reads the string from the file.

8. What is the difference between getc() and getchar()? (May 2015)


int getc(FILE * stream) gets the next character on the given input stream „s file pointer to
point to the next character.
int getchar(void) returns the next character on the input stream stdin.

9. Differentiate text file and binary file.


Text file Binary File
a. Data are human readable characters a. Data is in the form of sequence of bytes.
b. Each line ends with a newline character. b. There are no lines or newline character.
c. Ctrl+z or Ctrl+d are end of file character c. An EOF marker is used.
d. Data is read in forward direction only d. Data may be read in any direction.
e. Data is converted into the internal format e. Data stored in file are in same format
before being stored in memory that they are stored in memory

10. What is random access file?


A file can be accessed at random using fseek() function fseek(fp,position,origin);fp file
pointer position number of bytes offset from origin 0,1 or 2 denote the beginning current
position or end of file respectively.

www.AUNewsBlog.net 26
11. What is file pointer? www.AUNewsBlog.net
The pointer to a FILE data type is called as a stream pointer or a file pointer. A file pointer
points to the block of information of the stream that had just been opened.

12. What does the syntax depicts fread(&my_record,sizeof(struct rec), ptr_myfile);


(May 2015)
a. In the above statement, my_record is a pointer to an area of memory that will
receive the data from the file.
b. Size of (struct rec) indicates that number of bytes required for structure rec to be read.
c. Paramater „1‟ indicates that only one time bytes required for structure rec to be read.
d. ptr _myfile is pointer to previously opened file.

13. State the two types of data files.

a. Steam oriented or standard data files.


b. System oriented or low level data files.

14. State the two categories of standard data


files. The two categories of standard data files are
a. Text files.
b. Unformatted data files (Binary files).

15.What are unformatted data files or binary files?


The files that organize data into blocks of contiguous bytes of information are called
unformatted data files or binary files.

16. State the parameter of fopen function.


The parameter of fopen function are
a. Name of the file to be open
b. Mode of use

17. Define text files.


Text files are more restrictive than binary files since they can only contain textual data.
However, unlike binary files, they are less likely to become corrupted. While a small error in
a binary file may make it unreadable, a small error in a text file may simply show up once the
file has been opened.

18. Define binary files.


Binary files typically contain a sequence of bytes, or ordered groupings of eight bits. When
creating a custom file format for a program, a developer arranges these bytes into a format
that stores the necessary information for the application.

19. What do you mean by data file?


The data was written to the standard output and data was read from the standard input. As
long as only small amount of data are being accessed in the form of simple variables and a
character strings. This type of I/O is sufficient. With large amount of data, the information
has to be written to or read from auxiliary device. Such information is stored on the device in
the form of a data file.

www.AUNewsBlog.net 27
20. What is purpose of library fwunwcwtio.An
UNewsBlog.net
a. The C library function int feof(FILE*stream) tests the end-of-file indicator for the
given stream.
b. This function returns a non-zero value when End-of-file indicator associated with the
stream is set, else zero is returned.

21. What is the use of rewind function?


rewind(): This function is used to move the file pointer to the beginning of the given file.
Syntax : rewind(fptr); Where fptr is a file pointer.

22. List the different modes of opening a file.


The function fopen() has various modes of operation that are listed below
Mode Description
R Opens a text file in reading mode
W Opens or create a text file in writing mode.
A Opens a text file in appended mode.
r+ Opens a text file in both reading and writing mode.
w+ Opens a text file in both reading and writing mode.

23. Define logical file.


A logical file determines how data records are selected and defined when read by an
application program. A logical file can be a simple, multiple formats, or join logical file.

24. What are command line arguments?


It is possible to pass some values from the command line to your C programs when they are
executed. These values are called command line arguments and many times they are
important for your program especially when you want to control your program from outside
instead of hard coding those values inside the code.
#include <stdio.h>
Output
int main( int argc, char *argv[] ) $./a.out testing
{ The argument supplied is testing
if( argc == 2 ) {
$./a.out testing1 testing2
printf("The argument supplied is %s\n", argv[1]); Too many arguments supplied.
}
$./a.out
else if( argc > 2 ) { One argument expected
printf("Too many arguments supplied.\n");
}
else {
printf("One argument expected.\n");
}
}

www.AUNewsBlog.net 28
25. List the difference between Awpwpwen.Ad UanNdewwrsitBelomgo.dneet
Write (w) mode and append mode, while opening a file are almost the same. Both are used to
write in a file. In both the modes, new file is created if it doesn‟t exists already.
The only difference they have is, when you open a file in the write mode, the file is reset,
resulting in deletion of any data already present in the file. While in append mode this will
not happen. Append mode is used to append or add data to the existing data of file (if any).
Hence, when you open a file in append(a) mode, the cursor is positioned at the end of the
present data in the file.

26. Which methods are used to write in to binary files?


The following are the methods are used to write in to binary files
a. fread() function is used to read a binary file.
b. fwrite() functions is used to write a binary file.

27. What is the basic file operation in C?


There are four basic operations that can be performed on any files in C programming
language.
a. Opening / Creating a file.
b. Closing a file
c. Reading a file.
d. Writing in a file.

28. State the fflush() method.


fflush() is typically used for output stream only. Its purpose is to clear (or flush) the output
and move the buffered data to console (in case of stdout) or disk (in case of file output
stream). Syntax. fflush(FILE*ostream);

29. What is the difference between printf() and sprint()?


sprint() writes data to the character array whereas printf(…) writes data to the standard output
device.

30. What is the different file extensions involved when programming in C?


Source codes in C are saved with .C file extensions. Header files or library files have the .H
file extension. Every time a program source code is successfully compiled, it creates an.OBJ
object file, and an executable .EXE file.

31. What is a sequential access file?


When writing programs that will store and retrieve data in a file, it is possible to designate
that file in to different forms. A sequential access file is such that data are saved in sequential
access file, one data is placed in to the file after another. To access a particular data within the
sequential access, data has to be read one data at a time, until the right one is reached.

32. Is it possible to create your own header files?


Yes, it is possible to create a customized header file. Just include in it the function prototypes
that you want to use in your program, and use the #include directive followed by the name of
your header file.

www.AUNewsBlog.net 29
33. What is the advantage of a rwanwdwom.AUacNceesws fsilBe?log.net
If the amount of data stored in a file is fairly large, the use of random access will allow you to
search through it quicker. If it had been a sequential access file, you would have to go
through one record at a time until you reach the target data. A random access file lets you
jump directly to the target address where data is located.

34. How do you search data in a data file using random access method?
Use the fseek() function to perform random access input / output on a file. After the file was
opened by the fopen() function, the fseek would require three parameters to work: a file
pointer to the file, the number of bytes to search, and the point of origin in the file.

PART - B
1. What is file in C? Give brief introduction about files and its operations.
2. How to read and write the binary file? Explain with example.
3. Briefly explain the concept of the file management functions.
4. List out some inbuilt functions for file handling in c language.
5. How to access random access file? Write an example program.
6. Give brief notes about command line arguments in c.
7. Write a C program to write data to a text file and to read it.
8. Create a file, which contains a series of integer numbers. Search all odd numbers and save
it to file called odd.txt. Search all even numbers and save it to a file called even.txt.
9. Write a C program to implement the random access file.
10. Write a C program for handling records (structures) in a file.
11. Write a C program to calculate electricity bill as per the consumer usage.
12. Write a program to copy contents of input, txt file to output .txt file.
13. Explain about random access to files with examples.
14. Write a program that reads a text of characters from a file in departmental store and keep
track of the frequency of usage of each items stock and price.
15. Write a C program to read name and marks of n number of students from user and store
them in a file. If the file previously exits, add the information of n students.
16. With a C program find Sum of numbers given in Command Line Arguments Recursively
17. Write a C program for the following. There are two input files named “first.dat” and
“second.dat”. The files are to be merged. That is, copy the contents of first.dat and then
second.dat to a new file named result.dat.
18. Write a program to read the current date in the order: year, month, and day of month. The
th
program then prints the date in words: Today is the n day of Month of the year Year.
th
Example: Today is the 24 day of December of the year 2000
19. Explain the command line argument. What are the syntactic constructs followed in C?
20. Write a C program to copy the contents of one file into another using command line
arguments.
21. Explain about transaction processing using random access files.
22. Write a C program to find average of numbers stored in sequential access file.

www.AUNewsBlog.net 30

You might also like