Jobs in India
Search Jobs
Search Jobs
Advertisements

CUSAT ,27 August 2009 by SUBEX

Details of CUSAT ,27 August 2009 by SUBEX conducted by SUBEX for job interview.
Advertisements
1) fun(char *s,int n)
{
if(n==0)
return ;
fun(s,--n);
printf("%c",s[n]);
}
main()
{
char a[]="HELLO WORLD";
fun(a,11);
return 0;
}
ANS=HELLO WORLD

2) #define TRUE 1;
#define FALSE -1;
#define NULL 0;
main()
{
if(NULL)
printf("NULL");
else if(FALSE)
printf("TRUE");
else
printf("FALSE");
}
ANS=TRUE
3)main()
{
char str[10];
str=strcat("HELLO",,!,);
printf("%s",str);
}
ANS=

4) main()
{
int a[]={5,15,34,10};
int *ptr;
ptr=a;
int **ptr_ptr;
ptr_ptr=&ptr;
printf("%d",**ptr_ptr++);
}
ANS=5
5) struct e
{
char *a;
int flags;
int var;
union u
{
int b;
float *c;
}u1;
}tab[10];
main()
{
printf("%d",sizeof(tab));
return 0;
}
ANS=160 or 200(i dont know)
6) main()
{
float b=3.28;
printf("%d",(int)b)
return 0;
}
ANS=3
7) #define __line__ 10;
foo()
{
return __line__;
}
what will foo return?
ANS=10(may be wrong answer)
8) #ifdef something
int some=0;
#endif
main()
{
int thing = 0;
printf("%d %d\n", some ,thing);
}
Answer: Compiler error : undefined symbol some
Explanation: This is a very simple example for conditional compilation. The name something is not already known to the compiler making the declaration
int some = 0; effectively removed from the source code.
9) #include
main()
{
char s[]={,a,,,b,,,c,,,\n,,,c,,,\0,};
char *p,*str,*str1;
p=&s[3];
str=p;
str1=s;
printf("%d",++*p + ++*str1-32);
}
Answer: 77
Explanation: p is pointing to character ,\n,. str1 is pointing to character ,a, ++*p. "p is pointing to ,\n, and that is incremented by one." the ASCII value of ,\n, is 10, which is then incremented to 11. The value of ++*p is 11.++*str1, str1 is pointing to ,a, that is incremented by 1 and it becomes ,b,. ASCII value of ,b, is 98. Now performing (11 + 98 32), we get 77("M"); So we get the output 77 :: "M" (Ascii is 77).
10) #define square(x) x*x
main()
{
int i;
i = 64/square(4);
printf("%d",i);
}
Answer: 64
Explanation: the macro call square(4) will substituted by 4*4 so the expression
becomes i = 64/4*4 . Since / and *
has equal priority the expression will be evaluated as (64/4)*4 i.e. 16*4 = 64
11) main()
{
show();
}
void show()
{
printf("I,m the greatest");
}
Answer: Compier error: Type mismatch in redeclaration of show.
Explanation: When the compiler sees the function show it doesn,t know anything about it. So the default return type
(ie, int) is assumed. But when compiler sees the actual definition of show mismatch occurs
since it is declared as void. Hence the error.
The solutions are as follows:
1. declare void show() in main() .
2. define show() before main().
3. declare extern void show() before the use of show().
12) #define f(g,g2) g##g2
main()
{
int var12=100;
printf("%d",f(var,12));
}
Answer: 100