/> M3-R4: PROGRAMMING & PROBLEM SOLVING THROUGH ‘C’ LANGUAGE JAN 2017

M3-R4: PROGRAMMING & PROBLEM SOLVING THROUGH ‘C’ LANGUAGE JAN 2017


M3-R4: PROGRAMMING & PROBLEM SOLVING 
THROUGH ‘C’ LANGUAGE JAN 2017



Q.1. Multiple Choice of Answers.

1.1 Which of the following software translates source code into object code? 
A) Compiler 
B) Interpreter 
C) Assembler 
D) None

1.2 Which one of the following is not a keyword in C language? 
A) main 
B) endl 
C) float 
D) switch

1.3 Identify the invalid character constant: 
A) '\n' 
B) '$' 
C) '12' 
D) 'p'

1.4 What is the binary number equivalent of the decimal number 12? 
A) 1100 
B) 1010 
C) 1001 
D) 1110

1.5 Determine the order of evaluation of operations within the expression  A<B&&C||D>A 
A) &&, ||, <, > 
B) <, >, &&, || 
C) >, <, &&, || 
D) &&,<, >, || 

1.6 How many times the printf statement within the while loop will be executed? 
x=1; 
while(x=0) 
printf("hello"); 
A) 1 
B) 0 
C) infinite 
D) 2

1.7 Find the output generated by the given
program.
#include <stdio.h.
void main()
{
 printf("Bre\nak");
}
A) Break
B) Bre\nak
C) Break
D) None

1.8 Which of the following is not an iterative statement? 
A) switch 
B) while 
C) do while 
D) for

1.9 Identify the storage class with which & operator cannot be used. 
A) register 
B) static 
C) extern 
D) auto

1.10 Identify the invalid declaration: 
A) int &p; 
B) int *p[10]; 
C) int **p; 
D) int *p[ ];
Q.2. TRUE or FALSE.

2.1 The expressions on the both sides of a logical operator are always evaluated.
FALSE

2.2 exit() function is defined in stdio.h header file.
FALSE

2.3 for( ; i<2; i++); statement will result in compilation error.
FALSE

2.4 At the time of initialization of an array, dimension of the array need not to be specified.
TRUE

2.5 Actual parameters are used at the time of function calling.
TRUE

2.6 static storage class is used to make a variable global. 
FALSE

2.7 Array is passed to a function using 'call by value' method. 
FALSE

2.8 Pointers are used in a program to allocate memory before the program execution. 
FALSE

2.9 All the members of a union should be of same type.
FALSE

2.10 The function strlen() computes the length of an argument string excluding the null character.
TRUE               

Q.3. Match words and phrases


SR NO.
X
Y(Ans.)
1
Symbol '=' 
assignment operator 
2
Void
A function does not return anything
3
char *c[10]; 
c is a pointer pointing to string of size 10
4
calloc()
Allocates memory and clears it
5
char (*c)[10]
c is array of size 10 where each element is a pointer to character
6
Break 
To terminate a loop
7
Return
used with function
8
Extern
storage class 
9
clrscr() 
conio.h
10
call by reference
to get updated values of formal parameters of the function

Q.4. Fill in the blank

4.1 ___typecast____ operator converts an expression to a specified type.

4.2 The conditional operator (?:) is a ___Ternary____ operator.

4.3 Tool ___Flowchart____ is used for program design.

4.4 ___go to____ statement is used for unconditional branching in C.

4.5 Input function ____getch()____ does not show the character read from the input device.

4.6 ____Array____ is a derived data type.

4.7 Function isdigit() is defined in ___ctype.h_____ header file.

4.8 By default, storage class of local variables is ____Auto____.

4.9 The output of 14 % 4 is ___Two_____.

4.10 The size of long integer data type is ___four_____.

Options.
A. semicolon
A. Flowchart
B. ctype.h
C. typecast
D. Two
E. structured
F. four
G. Ternary
H. getch()
I. three
J. Array
K. go to
L. Auto
M. Psuedocode

Long Questions

(Answer any four questions)
Q.5. 
a) Write a function fnpow() in C to compute xy where x is float and y is integer. Function will
return the result and takes x, y as arguments
b) Write a function fnmat() which takes matrix, m, n as arguments where matrix is of size mXn
with m as rows and n as columns. Function should return the maximum and minimum
elements of the matrix. Elements of matrix are of integer type.
c) Find the output of the following:
char p[] = "%d\n";
 p[1] = 'c';
 printf(p, 65);
 int k=40, *a;
 a=&k;
 (*a)++; k++;
print("\n k=%d",k);
(5+6+4)

Q.6.
a) Write a program using command line parameters to append one text file to another 
text file.
b) Write down one similarity and one dissimilarity between break and continue statements.
c) A programmer wants to use two variables session and info. Variable session can take 
three values (morning, afternoon, evening) only. Using variable info, the programmer 
wants to access information empname and empid of 30 employees. Name the appropriate 
data type used for each variable session and info and declare the variables.
(8+2+5)

Q.7.
a) Given array a[10][10] of integer where each integer takes 4 bytes. Given the base address of array a as 4000, find address of a[4][5] assuming array is stored as row-major order.
b) Write a file statement to place a file pointer (fp) at the beginning of the record number (say R), where record size is B bytes. 
c) Differentiate between struct and union. When is union preferred over struct? Give one 
example for each.
(5+3+7)

Q.8.
a) Write a program to create a stack of integers using link-list and display it.
b) What is macro? Define a macro to compute maximum of two arguments passed to it.
(10+5)

Q.9.
a) Explain differences between:
i) Text file and binary file
Ans: Text File vs Binary File – Difference between Text File and Binary File
Text File
Binary File
Bits represent character.
Bits represent a custom data.
Less prone to get corrupt as changes reflect as soon as the file is opened and can easily be undone.
Can easily get corrupted, even a single bit change may corrupt the file.
Can store only plain text in a file.
Can store different types of data (image, audio, text) in a single file.
Widely used file format and can be opened using any simple text editor.
Developed especially for an application and may not be understood by other applications.
Mostly .txt and .rtf are used as extensions to text files.
Can have any application defined extension.

ii) static and extern storage class
Ans: Static variables in C
  1. Declared inside a function/block
  2. Keyword - static
  3. Syntax - static datatype variable-name;
  4. Storage - static memory
  5. Default value - zero
  6. Scope - accessible only to that particular function/block where it is defined
  7. Lifetime - entire program
Global/Extern variables in C
  1. Declared outside all functions/blocks
  2. Keyword - when used before its definition then extern keyword is used else keyword not required
  3. Syntax - extern datatype variable-name;
  4. Storage - static memory
  5. Default value - zero
  6. Scope - accessible to all the functions/blocks of the program
  7. Lifetime - entire program
 STATIC:
The purpose of ‘static’ is to keep a local variable in existence during life-time of program instead of creating & destroying it each time it comes into & goes out of scope. In the following program, i is declared as static and it doesn’t reset to every time func() is called. The keyword static extends it to scope to global.
#include<stdio.h>
void func(void);
static int count =3; /*Global variable*/
int main() {
//This loops run until count!=0
while(count--) {
  func(); 
  }
return 0;
}
void func(void){
 static int i=5; /*Local Static Variable */
 i++;
 printf(“i is %d , i);
}
Output:
i 6
i 7
i 8

EXTERN :
Suppose we need to use a variable that has been defined in another file. In such cases, ‘extern’ is used to give the global variable a reference that is visible to ALL program files. Consider the below example where we defined the global variable count as extern in support.csupport.c which will be referenced from main.cmain.c. Similarly, write_extern() is defined in support.csupport.c that is being referenced in main.cmain.c
main.c
int count;
extern void write_extern();
main(){
                count=5;
                write_extern();
}
support.c
extern int count;
voidwrite_extern(void){
                printf("Count is %d\n, count);
}
Output:
Count is 5

b) Write down the objective of following function:
void f1(char s[], char c)
{int i ,j ;
 for(i=j=0; s[i] != `\0' i++)
 if (s[i]!=c) s[j++]=s[i];
s[ j ] = `\
 return;
}
c) Explain the meaning of following declarations: 
i) int *p(char *a[])
ii) int *p(char *a, char *b)
iii) int (*p) (char *a)[] (++)
(5+4+6)


0/Post a Comment/Comments

Leave a Reply

Previous Post Next Post