Sie sind auf Seite 1von 4

C APTITUDE TEST - 7

1. struct easy{ 2 . typedef struct bit { int a:1; }


int color; char ch; }; BIT;
struct easy1{ void main(void){
int color; char ch; }; BIT sparse[3]
void main(){ [3]={1,0,0,0,1,0,0,0,1};
struct easy a= {8,’B’},b=a; for(int i=0;i<3;i++)
struct easy1 c=a; { printf(“\n”);
printf(“%d %d”,a.color, c.ch); } for (int j=0;j<3;j++)
printf(“%d ” ,
sparse[i][j].a ); }
} // end of main fuction
3 . struct NODE{ 4 . void swap(int *a,int *b)
int data; { *a^=*b^=*a^=*b; }
struct NODE link; }; void main() {
void main() { int a=8,b=010;
printf(“%d \n”, sizeof(struct swap(&a,&b);
NODE)); } printf(“%d %d”,a,b); }

5 . struct TEST{ 6 . struct KEY{


int number,evenflag=0; } int shift;
array[8]; char ch; }*p,*q;
main(){ main(){
array[1]={8,1}; p=(struct KEY *)5000;
printf(“ %d ”, q=(struct KEY *)2000;
array[5].number); printf(“%d \n”,p-q);
return 0; } return 0; }

7 . struct test{ 8.
float a; a) What is the subtle difference
int b,c;}; between malloc and calloc
Write a C program to find the size of fuctions ?
the structure ‘test’ defined above
without using sizeof operator. b) Raju and Veena had a
conversation .
Raju : I allocated memory dynamically
but the beauty is that without using
any pointers.
Veena : Are you joking ? It is
impossible .
What is wrong with that
conversation ?
9. int main(void) 10. union XYZ
{ { int _; char __; float ___; }
int data=014,shift=0x0; X;
while(data>>=shift){ int main(void) {
printf(“%d X._=65;
%d”,data,shift); printf(“%c %d”, X.__, X._);
-+-shift++ + 0x0080; }
}
return 0;
}

11. struct XXX{ 12. typedef int Bool;


float area; Bool function(unsigned num)
char country[10]; } c1; {
c1.country = “India”; unsigned help=1;
c1.area=11111111.1111111 while(help<=num)
void main() { {
printf(c1.country); If(num^help==0)
printf(“%f ”, c1.area); return 1;
} help<<=1;
}
return 0;
}
Give valid values and come up with
what the function does ?
13. struct ABC { 14. char
int *p; *a[]={“char”,”int”,”double”};
char *q; } A; int main(){
int main(){ printf(“%d”,strlen(a));
int a=34; printf(“%d
A.p=&a; “,strlen(a[0]);
printf(“%u”, *A->p); return return 0;
0;} }

15. struct CCC{ int a;int b; } 16. What is the difference between
If I declare int (*p)(struct CCC 1. char **p;
*); then 2. char *p[]; those
What does it mean ? declarations.

17. Write an algorithm to turn on the 18. There are ‘n’ numbers stored in an
desired bit array every number has its own pair
of a given unsigned number ‘n’. except only one number. Find out that
Eg 1 : input : 13 , 2 // 13= number and analyse time complexity.
(1101) base 2 . Eg :4 4 5 6 5 7 6 5 5 5 can be grouped
output : 15 ( 2nd bit from right is as (4,4) (5,5),(5,5),(6,6) but 7 has no
turned on ) . pair so output is : 7
Eg 2: input : 4 ,4 // 4=(100) base 2.
output : 12 // 1100 4th bit
turned on.
19. Correct the following code to print 20. unsigned function(unsigned
the binary pattern of given number num,int n)
and number of bits needed from {
right . while(n--){
void print_binary(unsigned if(num&0x8000)
num,int n){ num=(num<<01)|
if(n!=0) 0x0001)
{ else num<<=1;
((1<<(n-1))&&num)? }
printf(“1”):printf(“0”); return num;
print_binary(num,n++); }
} Give any random values as inputs and
} eg : input 5 , 4 output : 0101 find out what the function does .

Das könnte Ihnen auch gefallen