Sie sind auf Seite 1von 10

PRO’g’RAMMERS

FIRST ROUND – SET 1

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

FIRST ROUND – SET 1(C)

1.Write a code in C to print "QUARK-2011"


without using a semicolon.

2.Explain the output of the following code with


more details about the declaration step:

#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");
}
}

3.what does the following declaration imply?


volatile const int new=10;
4.Explain the output of the following piece of
code:

main()
{
printf("%p",main);
}

5.Explain output of the following program:

#include <stdio.h>
main()
{
char a[6] = "lmnop";
int b = 4;

printf("%c\n",a[b]);
printf("%c\n",((char *) b)[(int) a]);
}

6.Explain output of the following program:

#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;
};

struct test* f(struct test * (*fPtr)() )


{
struct test *ptr = (struct test*)
malloc(sizeof(struct test));
return ptr;
}
main()
{
f(f)->f;
}
9.What is the type of tmpr below?

typedef int (*new) ( float * , float*)


new tmpr;

10.Explain output of the following program:

#include <stdio.h>
void main()
{
static int j;
while(j<=100)
(j>25)?j++:j--;
printf("%d", j);
}

11.Explain output of the following program:

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

14.Point the errors


#include<stdio.h>
int main()
{
float a[]={6.3,4.9,7.9,5.7};
float *j,*k;
j=a;
k=a+4;
i=j*2;
k=k/2;
printf("%f%f",*j,*k);
return 0;

}
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;

16.Explain output of the following program:

#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();

18.What would be the output of the following


program?
main()
{
float river=0.7;
if(river<0.7)
printf("River rafting if fun!");
else
printf("River rafting is not fun");
}

19.Point out the error if any in the following

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?

#define SWAP(a,b,c) (ct;t=a,a=b,b=t)


main()
{
int x=10,y=20;
SWAP(x,y,int);
printf("%d %d",x,y);
}

Das könnte Ihnen auch gefallen