Beruflich Dokumente
Kultur Dokumente
INSTRUCTIONS:-
I. ALL THE QUESTIONS ARE EQUALLY IMPORTANT.
II. THERE IS NO PARTIAL MARKING.
III. THE PARTICIPANTS ARE ALLOWED TO CHOOSE ONLY ONE LANGUAGE EITHER C OR JAVA.
IV. ALL THE ANSWERS TO THE QUESTIONS SHOULD BE SENT IN A WORD FILE(.DOC
FORMAT)
V. MAIL THE ANSWERING AS AN ATTACHMENT TO: programmers@bits-quark.org WITH
‘ANSWERS TO THE FIRST ROUND OF PROGRAMMERS’ AS SUBJECT.
VI. BODY OF THE MAIL SHOULD HAVE THE PARTICIPANT’S DETAILS LIKE NAME, QUARK ID,
GROUP ID, PHONE NUMBER, AND THE LANGUAGE CHOSEN BY THE PARTICIPANT (C OR
JAVA).
VII. LAST DATE FOR SUBMISSION OF ANSWERS IS 11:59 PM, JANUARY 19TH.
PRO’g’RAMMERS
#include <stdio.h>
main()
{
unsigned int a[] = { 0x01,0x02, 0x04, 0x08,0x10,
0x20, 0x40, 0x80}; //Declaration step
unsigned int n,i;
printf("%d",a[7]);
scanf("%d",&n);
for(i=0;i<=7;i++)
{ if (n& a[i])
printf("\nyes");
else
printf("\nno");
}
}
main()
{
printf("%p",main);
}
#include <stdio.h>
main()
{
char a[6] = "lmnop";
int b = 4;
printf("%c\n",a[b]);
printf("%c\n",((char *) b)[(int) a]);
}
#include <stdio.h>
main()
{
enum _tag{ first=100, second, third=120,
fourth};
printf("first is %d, second is %d, third is %d,
fourth is %d",first,second,third,fourth);
}
7.Explain output of the following program:
#include <stdio.h>
#define PUT(a) printf("a = %d\t",(int) (a));
#define PRINT(a) PUT(a); putchar('\n');
#define CTRL(k) k + 3.14
main()
{
int x = 2;
PRINT( x * CTRL(x));
}
8.Explain output of the following program:
#include <stdio.h>
#include<malloc.h>
struct test{
int f;
};
#include <stdio.h>
void main()
{
static int j;
while(j<=100)
(j>25)?j++:j--;
printf("%d", j);
}
main()
{
int k=4,l=7;
l = l || k++ && printf("YOU CAN WIN THIS RACE");
printf("%d %d", k, l);
}
12.Which functions of the below 3 functions
misuses pointers and why?
int *funct1(void)
{
int i =10;
return(&i);
}
int *funct2(void)
{
int*ptr;
*ptr =10;
return ptr;
}
int *funct3(void)
{
int *ptr;
ptr=(int*)
malloc(sizeof(int));
return ptr;
}
13. A student is asked to write a code using
macros to find out the total class hours per
week. He has written the following code which
went terribly wrong. Locate and rectify the
error.
#define Daily_classes 3
#define Tutorial_classes 1
#define Total_classes
Tutorial_classes+Daily_classes
#define Time_per_class 40
#define Total_time Time_per_class*Total_classes
}
15.Explain output of the following program:
#include<stdio.h>
int main()
{
int a[]={5,10,15,20,25};
int j;
for(j=0;j<5;j++)
{
printf("%d\n",*a);
a++;
}
return 0;
#include<stdio.h>
#include<string.h>
int main()
{
char a[]="PROGRAMMERS!!";
printf("%d\n",*(a+strlen(a)));
return 0;
}
17.In the following code in what order the
functions would be called?
a=(bits(20,11)*goa(12/4))+rocks();
main()
{
int b;
b=f(20);
printf("%d",b);
}
int f(int a)
{
a>20?return(10):return(20);
}
20.Indicate what would the SWAP macro be
expanded to on preprocessing. Would the code
compile?