cs3251 2marks Question With Answer
cs3251 2marks Question With Answer
UNIT I
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.
d. \0 –
null
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
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))
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;
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 Press any key to continue . . .
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.
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)
10
11
12
14
15
16
25. Write a C program to input and their ASCII values in an integer array
and print the
Output
array. #include
<stdio.h> void Enter the no of characters to be
main() in an array 8
{ Enter the string of 8
char characters ProgRams
string[20]; int P = 80 r
n, count = 0; = 114 o
printf("Enter the no of characters to be in an array = 111 g
\n"); scanf("%d", &n); = 103 R
printf(" Enter the string of %d = 82 a
characters \n" , n); scanf("%s", string); = 97 m
while (count < n) =
{ 109 s =
printf(" %c = %d\n", string[count], string[count]); 115
++ count;
}
}
26. What is the formula to calculate determinant of 3 x 3 Matrix?
a bc
A d e f | A | aei fh bdi gf cdh 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);
17
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)
18
19
UNIT III
PART- A
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.
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.
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.
21
22
23
24
25
PART - B
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.
27
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 of c. A structure name is known as tag. It is a
the starting element Shorthand notation of the declaration.
d. An array cannot have bit fields d. A structure may contain bit fields
Structure 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.
29
struct student
{ Size of this is 3 bytes:1 byte for name and 2 bytes for integer num.
char
name;
int num;
} S;
31
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.
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.
6. Define union . Explain union in detail.
7. What are storage classes? Explain 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)
32
Unit 5 FILE
1. What is 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).
33
a. File name
b. File Position
c. File Structure
d. File Access Methods
e. Attributes flag
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.
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.
35
36
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.
37
38