HCL Placement Paper Collection Part II
	
    
    Section 2 – C  Programming
1.which of the following about the following two declarations is true
 	i) int *F();
 	ii)int (*F)();
 a)Both are identical	 b)the first is a correct declaration and second is wrong
 c)the first declaration is a function returning a pointer  to an integer and the second is a pointer to a function 
    returning int
 d)Both are different ways of declaring pointer to a function 	(ans. (c))
2.what are the values printed by the following program?
#define dprintf(expr) printf("expr=%d\n”,expr)
main()   {
int x=7;
int y=3;
dprintf(x/y);  }
a)#2=2 	b)expr=2	c)x/y=2 	d)none      	(ans.( c))
3.which of the following is true of the following program
main()  {
char *c;
int *ip;
c=(char *)malloc(100);
ip=(int *)c;
free(ip);  }
a)the code functions properly by releasing all the memory allocated
b)results in compilation error as a pointer of various types cannot be equated
c)the program ties to free more memory than allocated and results in run time error
d) works well except when the machine runs low on  memory and malloc is unabel to allocate the memory	(ans. (d))
4.output?
main()  {
int i;
char *p;
i=0x89;
p=(char *)i;
p++;
printf(“%x\n”p);    }
a)0x8c	 	b)0x4566788A 	c)0x8A 	d)0x8B 	e)none (ans. (c))
5.which of the following is not an ANSI C language keyword?
 a)volatile 	b)function 	c)default 	d)const 	e)void	(ans. (b))
6.when an array is passed as parameter to a function , which of the following statement is correct
the function can change values in the original array	
in c parameters are passed by value the function cannot change the original value in the array
it results in compilation error.Array cannot be passed as a parameter to a function	
 results in runtime error when the function tries to access the elements in the array
7.the type of the controlling expression of a switch statement cannot be of the type	
 a)int		b)char		c)short 	d)float 	e)none		(ans.(d))
8.value of (3^6)+(a ^a)=?						(Ans. value=5)
9.x= b>8?b<<3:b>4?b>>1:b;						(ans. x=3)
10.output:
main()  {
int n=2;
printf(“%d %d\n”,++n,n*n);  }
a)3,6 	b)3,4 	c)2,4 	d)cannot determine       			(ans.( b))
11.output:
int x=0x65;
main()   {
char x;
printf(“%d\n”,x);   }
a) Compilation error 	b)’A’ 	c)65  d)undefined
12.output
main() {
int a=10;
int b=6;
if(a=3)
b++;
printf(“%d %d”,a,b++);  }
a)10,6 	b)10,7 	c)3,6 	d)3,7 	e)none
13.main()    {
enum months {jan=1,feb,mar,apr};
months x=jan;
if(x==1)
printf(“jan is the first month”);    }
a)does not print anything	b)prints : jan is the first month
c)generates compilation error	d)results in runtime error		(ans. (c))
14.what is the output of the following program?
Main()		{
char *src=”hello world”;
char dst[100];
strcpy(src,dst);
printf(“%s”,dst);	}
strcpy(char *dst,char *src)	{
while (*src) *dst++=*src++;	}
a)”hello world” 	b)”hello”  		c)”world” 	d)NULL 	e)undefined (ans. (e))
15.main()   {
int i=6;
switch(i)   {
default: i+=2;
case 4;i=4;
case 5:i++;
break;      }
printf(“%d”,i);     }
a)8 		b)6 		c)5 		d)4  		e)none    			(ans. (c))
16.main()	{
int x=20;
int y=10;
swap(x,y);
printf(“%d %d”,y,x+2);		}
swap(int x,int y)			{
int temp;
temp=x;
x=y;
y=temp;				}
a)10,20 		b)20,12 		c)22,10  		d)10,22 		e)none
17.#define INC(x)		x++
main()		{
int x=4;
printf(“%d”,INC(x++));		}
a)4  		b)5  		c)6  	d)compilation error 	e)runtime error	(ans.(d))
18.struct node{
 		char *word;
 		int count;
 		struct node left;
 		struct node right;    		};
a)incorrect definiton		b)structures  cannot refer to other structrues
c)structures  can refer  to themselves. Hence the statement is ok
d)structures can refer to maximum of one other structure
19.what is the size of the following union
union tag{
 		int a;
 		float b;
 		char c;   };
a)2 		b)4 		c)1 		d)7						(ans.(b))
20. main()   {
char s[]=”hello  world”;
printf(“%15.10s”,s);     }
a)hello,.world… b)…..hello world  c)heloo,.wor….. d)none of the above	(ans.(b))	
	
	
	
		
	
		
    
    
        
            
                - 
            suji  
            
                    
 
                -  Nov 14th, 2005
 
                -  9
 
                -  4894
 
            
         
     
     
Questions by suji   answers by suji
	
    
          
              
            
              
                         
              
                    
              
              
     
    Showing Answers 1 - 9 of 9 Answers
			
				
				
       
       
		    
    
    
        
			
    
        
			
    
        
			
    
        
			
    
        
			
    
        
			
	
		
	
 
          
              
        
              
                      
              
                                   
  
                        
        Related Answered Questions
          
           
                              
            	
		Related Open Questions
		  
		   
	      
                       
  
                         
                    
            
HCL Placement Paper Collection Part II
1.which of the following about the following two declarations is true
i) int *F();
ii)int (*F)();
a)Both are identical b)the first is a correct declaration and second is wrong
c)the first declaration is a function returning a pointer to an integer and the second is a pointer to a function
returning int
d)Both are different ways of declaring pointer to a function (ans. (c))
2.what are the values printed by the following program?
#define dprintf(expr) printf("expr=%d\n”,expr)
main() {
int x=7;
int y=3;
dprintf(x/y); }
a)#2=2 b)expr=2 c)x/y=2 d)none (ans.( c))
3.which of the following is true of the following program
main() {
char *c;
int *ip;
c=(char *)malloc(100);
ip=(int *)c;
free(ip); }
a)the code functions properly by releasing all the memory allocated
b)results in compilation error as a pointer of various types cannot be equated
c)the program ties to free more memory than allocated and results in run time error
d) works well except when the machine runs low on memory and malloc is unabel to allocate the memory (ans. (d))
4.output?
main() {
int i;
char *p;
i=0x89;
p=(char *)i;
p++;
printf(“%x\n”p); }
a)0x8c b)0x4566788A c)0x8A d)0x8B e)none (ans. (c))
5.which of the following is not an ANSI C language keyword?
a)volatile b)function c)default d)const e)void (ans. (b))
6.when an array is passed as parameter to a function , which of the following statement is correct
the function can change values in the original array
in c parameters are passed by value the function cannot change the original value in the array
it results in compilation error.Array cannot be passed as a parameter to a function
results in runtime error when the function tries to access the elements in the array
7.the type of the controlling expression of a switch statement cannot be of the type
a)int b)char c)short d)float e)none (ans.(d))
8.value of (3^6)+(a ^a)=? (Ans. value=5)
9.x= b>8?b<<3:b>4?b>>1:b; (ans. x=3)
10.output:
main() {
int n=2;
printf(“%d %d\n”,++n,n*n); }
a)3,6 b)3,4 c)2,4 d)cannot determine (ans.( b))
11.output:
int x=0x65;
main() {
char x;
printf(“%d\n”,x); }
a) Compilation error b)’A’ c)65 d)undefined
12.output
main() {
int a=10;
int b=6;
if(a=3)
b++;
printf(“%d %d”,a,b++); }
a)10,6 b)10,7 c)3,6 d)3,7 e)none
13.main() {
enum months {jan=1,feb,mar,apr};
months x=jan;
if(x==1)
printf(“jan is the first month”); }
a)does not print anything b)prints : jan is the first month
c)generates compilation error d)results in runtime error (ans. (c))
14.what is the output of the following program?
Main() {
char *src=”hello world”;
char dst[100];
strcpy(src,dst);
printf(“%s”,dst); }
strcpy(char *dst,char *src) {
while (*src) *dst++=*src++; }
a)”hello world” b)”hello” c)”world” d)NULL e)undefined (ans. (e))
15.main() {
int i=6;
switch(i) {
default: i+=2;
case 4;i=4;
case 5:i++;
break; }
printf(“%d”,i); }
a)8 b)6 c)5 d)4 e)none (ans. (c))
16.main() {
int x=20;
int y=10;
swap(x,y);
printf(“%d %d”,y,x+2); }
swap(int x,int y) {
int temp;
temp=x;
x=y;
y=temp; }
a)10,20 b)20,12 c)22,10 d)10,22 e)none
17.#define INC(x) x++
main() {
int x=4;
printf(“%d”,INC(x++)); }
a)4 b)5 c)6 d)compilation error e)runtime error (ans.(d))
18.struct node{
char *word;
int count;
struct node left;
struct node right; };
a)incorrect definiton b)structures cannot refer to other structrues
c)structures can refer to themselves. Hence the statement is ok
d)structures can refer to maximum of one other structure
19.what is the size of the following union
union tag{
int a;
float b;
char c; };
a)2 b)4 c)1 d)7 (ans.(b))
20. main() {
char s[]=”hello world”;
printf(“%15.10s”,s); }
a)hello,.world… b)…..hello world c)heloo,.wor….. d)none of the above (ans.(b))
Questions by suji answers by suji
Related Answered Questions
Related Open Questions