WorksheetsTest in C Language
Total questions: 10
Worksheet time: 30mins
Consider the following declaration of a two dimensional array in C:
char a[100][100];
Assuming that the main memory is byte-addressable and that array is stored starting from memory address 0,the address of
a[40][50] is
4040
4050
5040
5050
The value of j at the end of the execution of the following C program:
int incr(int i)
{
static int count=0;
count=count+i;
return(count);
}
main()
{
int i,j;
for(i=0;i<=4;i++)
j=incr(i);
}
10
4
6
7
Consider the following C declaration :
struct {
short s[5]
union{
float y;
long z;
}u;
}t;
Assuming that objects of the type short,float and long occupy 2 bytes,4 bytes and 8 bytes respectively. The memory requirement for variable t, ignoring alignmenmt considerations, is :
22 bytes
18 bytes
14 bytes
10 bytes
What will be the output of the following C program segment ?
char inchar='A';
switch(inchar)
{
case\\\'A\\\'n:
printf("choice A\\\n");
case\\\'B\\\';
printf("choice B");
case\\\'C\\\';
case\\\'D\\\';
case\\\'E\\\';
Default :
printf("No Choice");
}
No Choice
Choice A
Choice A Choice B No Choice
Program gives no output as it is erroneous
Consider the following C program
main()
{
int x,y,m,n;
scanf("%d%d",&x,&y);
/* x>0 and y>0 */
m=x;n=y;
while(m!=n)
{
if(m>n)
m=m-n;
else
n=n-m;
}
printf("%d",n);
}
x+y using repeated subtraction
x mod y using repeated subtraction
the greatest common divisior of x and y
the least common multiple of x and y
Consider the following C function :
int f(int n)
{
static int i=1;
if(n>=5)
return n;
n=n+i;
i++;
return f(n);
}
The value return by f(1) is
5
6
7
8
Consider the following C function :
void swap(int a,int b)
{
int temp;
temp=a;
a=b;
b=temp;
}
In order to exchange the value of two variable x and y:
call swap(x,y)
call swap(&x,&y)
swap(x,y) cannot be used as it does not return any value
swap(x,y) cannot be used as the parameters are passed by value
What does the following fragment of C program print?
char c[]="GATE2011";
char *p=c;
printf("%s",p+p[3]-p[1];
GATE2011
E2011
2011
011
Consider the following C program segment:
char p[20];
char*s="string";
int length=strlen(s);
int i;
for(i=0;i<length;i++)
p[i]=s[length-i];
printf("%s",p);
The output of the program is :
gnirts
gnirt
string
No output
Consider the following recursive C function that takes two arguments
unsigned int foo(unsigned int n,unsigned int r)
{if(n>0) return (n%r+foo(n/r,r));
else return 0;
What is the value of foo(513,2)
9
8
5
2
