Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Program writing is a systematic process. It is not all about coding only. It requires a
certain methodology. Threre are three commonly used representation for the
development of a program as given below:
1.Algorithm
2.Pseudo-code
3. Flow chart
Any one of the above can be explained with example.
Page 2.3
e. What is a constant? List various constants in C. Explain any two in detail with suitable
examples.
Ans. (i) Distinct (ii) Distinct (iii) Distinct (iv)Distinct (v) Identical
b. Explain the purpose and use of following operators with suitable examples
(i) == and =
(ii) Conditional operator (? :)
Ans. Chapter3, Page 3.13 – 3.4, Page 3.10 - 3.3 Page 3.16 – 3.5
c. A c program contains the following declarations and initial assignments
int i=8, j=5;
float x=0.005, y=-0.01;
Determine the value of each of the following expressions
(i) 2*(i/5)+(4*(j-3)) % (i+j-2)
(ii) (x>y)&&(i>0)||(j<5);
Ans. Chapter 4, Page 4.4 - 4.4 (minimum four conversion characters should be
explained)
Ans.
//program to find big number using function
#include<stdio.h>
int Max(int n,int arr[]);
void main()
{
int n,a[100],big,i;
printf(“\nEnter number of elements in the array(not more than 100):”);
scanf(“%d”,n);
printf(“\n Enter %d elements of array:”);
for(i=1;i<=n;i++)
scanf(“%d”,&a[i]);
big=Max(n,a);
printf(“\nBig number=%d”,big);
}
int Max(int n1, int arr[])
{
int i,large=0;
for(i=1;i<=n1;i++)
{
if(arr[i]>large)
large=arr[i];
}
return large;
}
b. What is dynamic memory allocation? Explain the use of malloc function with
example.
Ans. Chapter 11, Page 11.18 – 11.5
c. Write a c program to perform addition and subtraction of two pointer variables.
Ans.
//Program to perform addition and subtraction of two pointer variables
#include<stdio.h>
#include<conio.h>
void main()
{
int n1,n2,*ptr1,*ptr2,sum,sub;
printf(“\nEnter two integers to be added or subtracted:”);
scanf(“%d%d”,&n1,&n2);
ptr1=&n1;
ptr2=&n2;
sum=*ptr1+*ptr2;
sub=*ptr1-*ptr2;
printf(“\nSum=%d”,sum);
printf(“\nDifference=%d”,sub);
getch();
}
d. What is a structure? How does a structure differ from an array?
Ans. Chapter 12,Page 11.69 – 12.1
e. What is a union? Differentiate between structure and union?
Ans. Chapter 12, Page 12.55
f. (a) Define a structure of type hms containing three integer members, called hours,
minutes and second, respectively. Then define a union containing two
members, each a structure of type hms. Call the union members local and
home respectively. Declare a pointer variable called time that points to this
union.
(b) Define a union of type ans which contains an integer quantity called ians, a
floating point quantity called fans, a double precision quantity called dans.
Then define a structure with members a union of type ans called answer, a
single character called flag, integer quantities called a and b. Finally declare
two structure variables called x and Y
Ans. (a) struct nms
{
int hours;
int minute;
int second;
}
union
{
struct hms local;
struct hms home;
}*time;
_____________________________