OCS752 - 2 Mark Questions and Answers
OCS752 - 2 Mark Questions and Answers
OCS752 - 2 Mark Questions and Answers
UNIT-I
1. What are the various types of operators?
C supports the following types of operators
Unary
Unary Plus +
Unary Minus -
Increment ++
Decrement --
Binary
Arithmetic +,-,*,/,%
Relational <,>,<=,>=,==,!=
Logical &&,||,!
Bitwise &,|,^,<<,>>
Assignment =
Shorthand assignment +=, -=,*=,/=,%=
Ternary
?:
Special
Sizeof(), *. ->
8. Define Searching
Searching is a process of finding a given element in a list. The searching is successful if the
element is found. There are two types of searching.
⮚ Linear Search
⮚ Binary Search
9. Define Sorting
Sorting is a process of arranging the elements either in ascending order or descending order.
1. What is a function?
Function is a set of instructions
Self contained block
Performs a specific task
Used to avoid redundancy of code
4. Define recursion
Recursion is a process by which a function calls itself. Recursive function is a function that
calls itself.
Pass-by-value Pass-by-reference
Copy of actual arguments are passed Address of actual arguments
are passed
Changes to formal arguments doesn‟t Changes to formal arguments
reflect to actual argument reflect to actual argument
Need more memory Saves memory space
2002
The pointer holds the address 2000. This value is added with 1. The data type size of the
constant is added with the address.
p= 2000+(2*1)=2002
UNIT-V Structures
1. State the meaning of the root word struct.
The keyword struct is used to denote the user defined data type structure.
Example:
struct employee
{
char name[10];
int eno;
float bpay;
};
2. What is the use of typedef?
typedef is a keyword used in C language to assign alternative names to existing
datatypes. Its mostly used with user defined datatypes, when names of the datatypes become
slightly complicated to use in programs. Following is the general syntax for using typedef,
typedef <existing_name> <alias_name> Ex: typedef unsigned long ulong;
The above statement define a term ulong for an unsigned long datatype. Now this ulong
identifier can be used to define unsigned long type variables.
3. Define structure of C language Give example.
C Structure is a collection of different data types which are grouped together
and each element in a C structure is called member
Ex: struct employee
{
char name[10];
int eno;
float bpay;
};
4. What is dynamic memory allocation? What are the various dyn amic memory allocation
functions?
Allocating memory during run time is called dynamic memory allocation.
The various functions used for that are
malloc
calloc
realloc
free
5. Compare arrays and structures.
Arrays Structures
1. An array is a collection of data items 1.A structure is a collection of data items of
same data type. of different data types.
2. Arrays can only be declared. 2. Structures can be declared and defined.
3. There is no keyword for arrays. 3. The keyword for structures is struct.
4. An array cannot have bit fields. 4. A structure may contain bit fields.
5. An array name represents the 5. A structure name is known as tag.
address of the starting element. It is a Shorthand notation of the declaration.
...
struct name *pointer;
};