M3-R4: PROGRAMMING AND PROBLEM SOLVING THROUGH
(PART ONE – 40; PART TWO – 60)
PART ONE (Answer all the questions)
1. Each question below gives a multiple choice of answers. Choose the most appropriate one and enter in the “tear-off” answer sheet attached to the question paper, following instructions therein. (1x10)
1.1 By default a real number is treated as a
A) float
B) double
C) long double
D) integer
1.2 Which of the following expression is equivalent to ++*ptr?
A) (*ptr)++
B) ++*(ptr)
C) (ptr)*++
D) (ptr)++*
1.3 The default storage class of a ‘C’ variable is
A) auto
B) static
C) extern
D) register
1.4 Which header file should be included to use functions like malloc() and calloc()?
A) memory.h
B) stdlib.h
C) string.h
D) dos.h
1.5 We can combine the following two statements into one using
char *p;
p = (char*) malloc(100);
A) char p = *malloc(100);
B) char *p = (char) malloc(100);
C) char *p = (char*)malloc(100);
D) char *p = (char *)(malloc*)(100);
1.6 How many times "DOEACC" will get printed? #include<stdio.h>
int main() {
int x; for(x=-1; x<=10; x++) {
if(x < 5)
continue; else
break; printf("DOEACC"); }
return 0; }
A) Infinite times
B) 11 times
C) 0 times
D) 10 times
1.7 Which of the following statement is correct about the following program?
#include<stdio.h>
long fun(int num) {
int i; long f=1; for(i=1; i<=num; i++)
f = f * i; return f; }
A) The function calculates the value of 1 raised to power num
B) The function calculates the square root of an integer
C) The function calculates the factorial value of an integer
D) None of the above
1.8 In C, if you pass an array as an argument to a function, what actually gets passed?
A) Value of elements in array
B) First element of the array
C) Base address of the array
D) Address of the last element of array
1.9 If a file is open in ‘write’ mode, then
A) If it does not exist, an error is returned
B) If it does not exist, it is created
C) If it exists, then data is written at the end
D) If it exists, error is returned
1.10 Which of the following functions is used to free the allocated memory?
A) remove(var-name);
B) free(var-name);
C) delete(var-name);
D) dalloc(var-name);
2. Each statement below is either TRUE or FALSE. Choose the most appropriate one and ENTER in the “tear-off” sheet attached to the question paper, following instructions therein. (1x10)
2.1 Size of short integer and long integer can be verified using the sizeof() operator.
2.2 The expression a[0] and *a[0] are same for int a[100].
2.3 A structure can contain similar or dissimilar elements.
2.4 Right shift of an unsigned integer by one bit is equivalent to multiplying it by two.
2.5 Functions can be called either by value or by reference.
2.6 Bounds of the array index are checked during execution.
2.7 Every time we supply new set of values to the program at command prompt, we need to recompile the program.
2.8 If the two strings are found to be unequal then strcmp returns difference between the first non- matching pair of characters.
2.9 Singly-linked lists contain nodes which have a data field as well as a next field, which points to the next node in the linked list.
2.10 In computer programming, the translation of source code into object code is done by a compiler.
3. Match words and phrases in column X with the closest related meaning/ word(s)/phrase(s) in column Y. Enter your selection in the “tear-off” answer sheet attached to the question paper, following instructions therein. (1x10)
Sr. No. | X | Y(Ans.) |
1 | group of related data of same type that share a common name | |
2 | operator used to get value at address stored in a pointer | |
3 | linked list is a | |
4 | switch statement is often used for | |
5 | extern int i; is | |
6 | gives the current position of the pointer | |
7 | statement ends the loop | |
8 | recursion is a process | |
9 | by default, functions return | |
10 | to concatenate two strings we use |
4. Each statement below has a blank space to fit one of the word(s) or phrase(s) in the list below. Enter your choice in the “tear-off” answer sheet attached to the question paper, following instructions therein. (1x10)
4.1 ________ breaks the normal sequential execution of the program.
4.2 Ovals are used to represent starting and ending points in the ________.
4.3 ________ are used when we want to test more than one condition and make decision.
4.4 A pointer variable contains ________ until it is initialized.
4.5 When a function returns a structure, it must be assigned to a structure of identical type in the ________.
4.6 A float is ________ bytes wide, whereas a double is ________ bytes wide.
4.7 The ________ operator can be used to access structures elements using a pointer to a structure variable.
4.8 The keyword used to transfer control from a called function back to the calling function is ________.
4.9 If a function return type is declared as ________ it cannot return any value.
4.10 Input/output function prototypes and macros are defined in ________.
PART TWO (Answer any FOUR questions)
5.
a) What is dynamic memory allocation? Mention four functions used for dynamic memory manipulation.
b) What are command line arguments? Explain with the help of a suitable example.
c) Define a two dimensional array ‘int a[10][10]’. Write a ‘C’ program to initialize this array with numbers between 0 and 99. Then print the contents of ‘a’.
(5+5+5)
6.
a) Define Auto and Register variables in context of C. What is the basic difference between these variables?
b) Write a program that takes as input an integer between 1-12 (both inclusive) and prints the month corresponding to that integer.
c) Draw two flow charts to distinguish between break and continue statements.
(5+5+5)
7.
a) Write a function to swap two integers. The function does not return any value.
b) Write a ‘C’ program to create a file of integers. The file name is given by the user. The second input to the program is the number ‘n’ of positive integers to be written into the file starting from 1.
c) What is union data type? Define a union ‘u’ to hold a integer, float and character variable.
(6+6+3)
8.
a) Write a C program to construct a linear linked list in C to store student records. The record contains roll no. and total marks. The program stops when a negative roll no. is entered.
b) Write a program to find out whether a given number is Prime or not.
(6+9)
9.
a) What will be the output of the program? Explain step by step.
#include<stdio.h>
void fun(int*, int*); int main() {
int i=5, j=2; fun(&i, &j);
printf("%d, %d", i, j);
return 0; }
void fun(int *i, int *j) {
*i = *i**i; *j = *j**j; }
b) What will be the output of the program? Explain step by step
. #include<stdio.h>
int main() {
int arr[5], i=-1, z;
while(i<5)
arr[i]=++i;
for(i=0; i<6; i++)
printf("%d, ", arr[i]); return 0; }
c) Point out the error in the following program. How you will modify the program to overcome from the error?
#include<stdio.h> struct emp {
char name[20]; int age; };
int main() {
emp int xx; int a;
printf("%d\n", &a);
return 0; }
(5+5+5)
- o O o -
Post a Comment
Leave a Reply