Programming in C Summer 2019 Answer Paper
Programming in C Summer 2019 Answer Paper
(Autonomous)
SUMMER– 19 EXAMINATION
1) The answers should be examined by key words and not as word-to-word as given in the model answer
scheme.
2) The model answer and the answer written by candidate may vary but the examiner may try to assess the
understanding level of the candidate.
3) The language errors such as grammatical, spelling errors should not be given more Importance (Not
applicable for subject English and Communication Skills.
4) While assessing figures, examiner may give credit for principal components indicated in the figure. The
figures drawn by candidate and model answer may vary. The examiner may give credit for anyequivalent
figure drawn.
5) Credits may be given step wise for numerical problems. In some cases, the assumed constant values may
vary and there may be some difference in the candidate’s answers and model answer.
6) In case of some questions credit may be given by judgment on part of examiner of relevant answer based
on candidate’s understanding.
7) For programming language papers, credit may be given to any other program based on equivalent concept.
Q. Sub Marking
Answer
No. Q.N. Scheme
Page1
MAHARASHTRASTATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
c) 2M
Give syntax of for loop.
d) State any two differences between call by value and call by reference. 2M
Any two
Sr. Call by value Call by reference differences
No. 1M each
1 A copy of actual arguments Address of actual arguments is
(value) is passed to respective passed to formal arguments.
formal arguments.
Ans:
2 Actual arguments will remain Alteration to actual arguments is
safe, they cannot be modified possible within from called
Page2
MAHARASHTRASTATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
Ans: Definition: A pointer is a variable that stores memory address of another variable 1M
which is of similar data type.
Uses of pointer:- any two
1. Pointers are used for dynamic memory management. correct
2. Pointers permit references to functions and thereby facilitating passing of uses 1/2M
functions as arguments to other functions. each)
3. They can be used to return multiple values from a function via function
arguments.
f) 2M
State the use of , *, & symbols used in pointers.
Ans: * operator:- 1M
OR
It is also used as value at operator i.e. it reads the value from the address stored in
pointer variable.
Example: printf(“%d”, *ptr);
The above statement displays value present at the address stored in ptr
variable.
1M
& operator:-
It is used to retrieve address of a variable from memory.
Example: int *ptr,a;
ptr=&a;
Page3
MAHARASHTRASTATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
The above statement stores the address of variable a in the pointer variable
ptr.
g) Define structure. 2M
Ans: Definition: 2M
A structure is a collection of one or more variables of same or different data types
grouped together under a single name.
Page4
MAHARASHTRASTATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
long double: It is used to declare floating point type variable. It occupy 80 bits
(10 bytes) memory size to store data such as 11.11,21.2,etc.
Example: long double percentage;
void data type:
void data type has no values. When a function does not return any value then the
return type of function is specified with void data type.
example:
void add( )
{
Statements;
}
Ans: Definition: 2M
if...else statement. When series of decisions are involved in a program we can use
Syntax : 2M
if(test condition1)
{
if(test condition2)
{
statement-1;
}
else
{
statement-2;
}
}
else
{
statement-3;
}
statement-x;
If test condition-1 is true, then condition-2 is checked. If condition-2 is true, then
statement-1 is evaluated. If condition-2 is false then statement-2 is evaluated and
then control is transferred to the statement-x. If condition-1 is false then control
passes to statemtn-3 and it is executed .Then control passes to statement-x
Page5
MAHARASHTRASTATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
example: 1M
int num=75;
if(num<100) ------------------Condition 1
{
if(num<50) -----------------Condition 2
{
printf("Number is less than 50"); ----Statement 1
}
else
{
printf("Number is greater than 50 but less than 100");--- statement 2
}
}
else
{
printf("Number is greater than 100");---statement 3
}
In the above example, variable num is initialized to value 75.In condition 1 num is
Compared with 100 and the condition evaluates to true. So control passes to
condition 2.In condition 2 num is greater than 50 so condition is false. Control
passes to statement 2 and output is " Number is greater than 50 but less than 100".
Then control comes out of nested if...else statement.
Ans: Explanation: 3M
An array is a sequenced collection of similar type of data. Values in an array are
stored in Continuous memory locations. All data values stored in an array share a
common name. To access individual value from an array, index variable is used. An
index variable starts with 0th position. First value in an array is stored at 0th position
and last value is stored in size-1 index position. For example, in an array of 5
elements, first value is stored at 0th position and last value is stored at 4th index
position.
Page6
MAHARASHTRASTATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
Example:
int arr[5] = {10, 20, 5, 3, 55};
In the above example, an array variable arr is declared and initialized with integer
values with the size 5.
½ Each
Array represents multiple data items of similar type using single name.
Adding and removing data element at any index position is possible.
d) List any 2 string functions. Give syntax and use of each function. 4M
1. strcat ( )
2. strcmp( )
3. strcpy ( )
4. strlen ( )
5. strlwr( )
6. strupr( )
Syntax ½
Each
1. strcat ( ):- This string function is used to join two strings together.
Syntax: strcmp(string1,string2);
string1 and string2 are character arrays.
3. strcpy( ):- This string function is used to copy the content of one string to the
other string.
Syntax: strcpy(string1,string2);
Page7
MAHARASHTRASTATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
string1 and string2 are character arrays. When strcpy( ) function executes the
contents of string2 are copied into string1.
4. strlen( ):- This string function is used to count and return number of characters
stored in a string.
Syntax: variable_name=strlen(string);
string is a character array.variable_name is an integer variable that stores the value of
the length of the string return by strlen( ) function.
5. strlwr( ):- This string function is used to convert a given string into lower case
letters.
Syntax: strlwr(string);
string is a character array.
6. strupr( ):- This string function is used to convert a given string into upper case
letters.
Syntax: strupr(string);
string is a character array.
Q.3 Attempt any Three: 12M
a) Enlist any four bitwise operators used in C and give example of each. 4M
Page8
MAHARASHTRASTATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
The Bitwise AND will take pair of bits from each position, and if only both the bit is
1, the result on that position will be 1.
Bitwise AND is used to Turn-Off bits.
-------
Bitwise NOT:
One‟s complement operator (Bitwise NOT) is used to convert each “1-bit to 0-bit”
and “0-bit to 1-bit”, in the given binary pattern. It is a unary operator i.e. it takes only
one operand.
1001
NOT 0110
-------
Bitwise XOR ^
Bitwise XOR ^, takes 2 bit patterns and perform XOR operation with it.
0101
0110
------
XOR 0011
------
Page9
MAHARASHTRASTATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
Ans: The pointer arithmetic is done as per the data type of the pointer. The basic Arithmetic
operations on pointers are operation
Increment: 1M Each
It is used to increment the pointer. Each time a pointer is incremented, it points to the
next location with respect to memory size .
Example,
If ptr is an integer pointer stored at address 1000,then ptr++ shows 1002 as
incremented location for an int. It increments by two locations as it requires two
bytes storage.
Decrement:
It is used to decrement the pointer. Each time a pointer is decremented, it points to
the previous location with respect to memory size.
Example,
If the current position of pointer is 1002, then decrement operation ptr-- results in the
pointer pointing to the location 1000 in case of integer pointer as it require two bytes
storage.
Addition:
When addition operation is performed on pointer, it gives the location incremented
by the added value according to data type.
Eg:
If ptr is an integer pointer stored at address 1000,
Then ptr+2 shows 1000+(2*2) = 1004 as incremented location for an int.
Subtraction:
When subtraction operation is performed on the pointer variable, it gives the location
decremented by the subtracted value according to data type.
Eg:
If ptr is an integer pointer stored at address 1004,
Page10
MAHARASHTRASTATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
P2= p1;
P2= p1;
Page11
MAHARASHTRASTATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
char tit[20];
char auth[20];
int price;
}b1;
Q.4 A) Attempt any THREE : 12 M
a) Write a C program to accept two integer numbers from user and print the 4M
result of addition and subtraction.
void main()
int num;
Correct
clrscr();
syntax 2M
printf("\n Enter number: ");
scanf("%d",&num);
if(num > = 0)
Page12
MAHARASHTRASTATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
else
getch();
Output:
Enter number: 4
4 is positive number
Enter number: -6
-6 is negative number
#include<stdio.h>
Void main()
printf(“output”);
Print(“%d”, a[i]);
Ans: Correct
output
output 4M
10 20 30
Page13
MAHARASHTRASTATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
void main()
int i;
Correct
struct book {
syntax 2M
char book_title[50];
int book_number;
int book_price;
}b[10];
clrscr();
scanf("%d%s%d",&b[i].book_number,b[i].book_title,&b[i].book_price);
b[i].book_title,b[i].book_price);
Page14
MAHARASHTRASTATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
getch();
if (test expression)
{
True-block statement (s)
}
else
{
False-block statement (s)
} Statement-x;
Explanation :
1. If-else statement is a decision making statement and is used to control the 1M
flow of execution of statements.
2. It allows the computer to evaluate the expression first and then depending on
whether the value of the expression is true or false, it transfers the control to
the particular statement block.
3. If the test expression is true, then true block statement(s) are executed,
immediately following the if statement are executed otherwise false block
statement(s) are executed.
3M
Example:
#include<stdio.h>
#include<conio.h> NOTE:
void main() Any other
{ example
int num; shall be
printf("Enter the number"); considered
scanf("%d",&num)
if(num>0)
{
Page15
MAHARASHTRASTATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
printf("Number is positive");
}
else
{
printf("Number is negative");
}
getch();
}
b) Write a C program to read string from keyboard and find whether it is 6M
palindrome or not.
Page16
MAHARASHTRASTATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
length = strlen(string1);
for(i=0;i < length ;i++)
{
if(string1[i] != string1[length-i-1])
{
flag = 1;
break;
}
}
if (flag)
printf("%s is not a palindrome", string1);
else
printf("%s is a palindrome", string1);
getch();
}
(Autonomous)
Page18
MAHARASHTRASTATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(Autonomous)
{
int roll_no;
char name[20]; Accept
int sm1,sm2,sm3; elements
}s; 2M
void main()
{ Display
float percent; answer
clrscr(); 2M
printf("Enter student roll no, name, subject1 marks,subject2 marks ,subject3
marks :");
scanf("%d%s%d%d%d",&s.roll_no,s.name,&s.sm1,&s.sm2,&s.sm3); NOTE:
percent=(s.sm1+s.sm2+s.sm3)/3; Any other
printf("\nRollNo\tName\tPercentage"); example
printf("\n%d\t%s\t%.2f",s.roll_no,s.name,percent); shall be
getch();
considered
}
Page20